Re: In-consistent behavior in malloc/free .
On Apr 28, 5:48 am, Guru <ashok...@gmail.com> wrote:
I have observed an in-consistent behavior in mall=
oc/free .
Case 1 :
struct TMemFile
{
char* pFIle;
}
main1()
{
TMemFile mptr[20000] ; // Stack Variable
for ( 20000 times)
{
mptr[i].pFile = malloc =
100 KB.
}
for (20000 times)
{
Free(mptr.pFile);
}
}
Case 2:
struct TMemFile
{
char* pFIle;
}
main2()
{
TMemFile* mptr[20000] ; // Heap Variable
for (20000 times)
{
mptr[i] = malloc (TMemF=
ile);
mptr[i]->pFile = malloc=
100 KB;
}
for (20000 times)
{
free(mptr[i]->pFIle);
free(mptr[i]);
mptr[i] = NULL;
}
}
In Case 1, after executing main1() memory is getting released and
VirtualMemory is coming down (reading from top).
In Case 2, after executing main2() memory is getting released and
VirtualMemory is not coming down (reading from top).
I don't see any problem with the logic of you pseudo-code, but I might
not be reading it correctly. We might be able to help you more if you
posted actual C++ code.
Also, once you start talking about Virtual Memory, you are going off
the topic of this Usenet group. If I recall correctly, the C++
language does not describe Virtual Memory at all. It is platform
specific behavior, most likely associated with your operating system
(e.g. Microsoft Windows XP). As such, you might get better help from
a platform specific group (e.g. comp.os.ms-windows.programmer.memory
or microsoft.public.vc.language).