How To Get The Size Of Memory Allocated In Heap

sizeof() function can not give the size of memory locations allocated using new, malloc, calloc and realloc. VC++ provides a macro for the above purpose and it is _msize. See the following code segment.

#include
using namespace std;
int main()
{  
   // Allocate 10 integer locations 
   // = a toatl of 40 in 32 bit platforms
   int* pInt = new int[10];
   size_t Size = _msize(pInt);
   cout << Size << '\n';       return 0; } [/sourcecode] The result will be 40.

Advertisements

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: