Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

  • Blog Stats

    • 9,866

sizeof…

Posted by kiraninbng on July 5, 2006

Here is a simple way to find the size of an object without using the sizeof operator,

class CTest { … }

CTest oCTest;
CTest* pCTest;
unsigned char* pStart = NULL;
unsigned char* pEnd = NULL;

pCTest = &oCTest;
pStart = (unsigned char*)pCTest;
pEnd = (unsigned char*)(++pCTest);

//size gives the size of the object oCTest.
size_t size =  pEnd – pStart;

One Response to “sizeof…”

  1. FarPointer said

    Nice One.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>