3

我使用指针来指定某种“共享内存”,用于在不同进程/线程之间交换数据。现在我想要共享缓冲区内容的十六进制转储。有谁知道这是怎么做到的吗?

谢谢,

4

2 回答 2

14

Use casts, of course :-) The function should look something like this:

void Dump( const void * mem, unsigned int n ) {
  const char * p = reinterpret_cast< const char *>( mem );
  for ( unsigned int i = 0; i < n; i++ ) {
     std::cout << hex << int(p[i]) << " ";
  }
  std::cout << std::endl;
}

Then in use:

Foo * f = GetSharedFoo();
Dump( f, somesize );

where somesize is how much you want to dump.

于 2009-08-17T08:25:10.507 回答
0

On Windows, you can use ReadProcessMemory. I do not know the Linux equivalent.

于 2009-08-17T08:23:52.897 回答