Re: How to get the memory block size which allocated by new operator?
- From: "Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx>
- Date: Fri, 08 Sep 2006 11:43:46 +0100
space6 wrote:
In my project,it seemed there is memory leak somewhere.I can't find the
place even by using Numega BoundCheck.then I find a idea.I think I can
use a global variable of integer to save the
memory that not released.When allocate memory by new operator,I will
add the size to the global
variable,and when delete memory,I will sub the size.And I always output
the global viarable by OutputDebugString() API.
I successd at Debug mode.The code to get a buffer's size which
allocated by new operator as following:
int GetNewBufferSize(void *p)
{
if ( p )
#ifdef _Debug
return *(int*)((char *)p-16);
#else
//How to get the memory size in release mode ?
#endif
else
return 0;
}
But it can not work well in the release mode.How can tell me how to get
the memory size in release mode?
_msize will work with memory returned by malloc (rather than new or new[]). I'm not sure it is guaranteed to return the same value as that passed to malloc, it might possibly return a larger value (e.g. rounded up to the next largest power of 2, or something).
Tom
.
- References:
- Prev by Date: Re: how to study vc 6
- Next by Date: Re: Fairly serious VC6 compiler bug
- Previous by thread: How to get the memory block size which allocated by new operator?
- Next by thread: Re: How to get the memory block size which allocated by new operator?
- Index(es):
Relevant Pages
|