Skip to content

Instantly share code, notes, and snippets.

@mitsuji
Created September 30, 2010 01:55
Show Gist options
  • Save mitsuji/603898 to your computer and use it in GitHub Desktop.
Save mitsuji/603898 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
// int version
void memdumpi(void* vptr, size_t len)
{
std::cout << ">>>> memdump(int) ---------------------------" << std::endl;
unsigned int* cptr = reinterpret_cast<unsigned int*>( vptr );
for (size_t i=0; i<(len/sizeof(int)); ++i )
{
if ( i%4 == 0 )
{
if ( i != 0 ) std::cout << std::endl;
std::cout << std::hex << std::setw(8) << std::setfill('0');
std::cout << reinterpret_cast<int>(&cptr[i]) << ": ";
}
std::cout << std::hex << std::setw(8) << std::setfill('0');
std::cout << static_cast<int>(cptr[i]) << " " ;
}
std::cout << std::endl;
std::cout << "--------------------------- memdump(int) <<<<" << std::endl;
}
// char version
void memdumpc(void* vptr, size_t len)
{
std::cout << ">>>> memdump(char) --------------" << std::endl;
unsigned char* cptr = reinterpret_cast<unsigned char*>( vptr );
for (size_t i=0; i<len; ++i )
{
if ( i%8 == 0 )
{
if ( i != 0 ) std::cout << std::endl;
std::cout << std::hex << std::setw(8) << std::setfill('0');
std::cout << reinterpret_cast<int>(&cptr[i]) << ": ";
}
std::cout << std::hex << std::setw(2) << std::setfill('0');
std::cout << static_cast<int>(cptr[i]) << " " ;
}
std::cout << std::endl;
std::cout << "-------------- memdump(char) <<<<" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment