views:

376

answers:

2

Hi

I use a pointer to specify some kind of "shared memory" which I use to exchange data between different processes/threads. Now I would like to have a hex dump of the content of the shared buffer. Does anyone know how to do that?

thanks, R

A: 

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

GMan
+4  A: 

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.

anon
Just looked into my toolbox. Mine also puts a `std::setw(2) << std::setfill( os.widen('0') )` into the stream. But that might be because I write into stream with any character width.
sbi
anon