Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

    • 14,897

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;

Advertisements

One Response to “sizeof…”

  1. FarPointer said

    Nice One.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: