Windows CE Heap Allocation - Windows CE
This is a discussion on Windows CE Heap Allocation - Windows CE ; I'm using an XML library ( http://sourceforge.net/projects/tinyxml/ ) on
Windows CE 4.2, and after loading a 670KB XML file into memory with
it, it decreases my available memory by about 4MB. Once I delete the
document object (which frees all ...
-
Windows CE Heap Allocation
I'm using an XML library (http://sourceforge.net/projects/tinyxml/) on
Windows CE 4.2, and after loading a 670KB XML file into memory with
it, it decreases my available memory by about 4MB. Once I delete the
document object (which frees all nodes / elements / etc.), my
available memory (displayed by the Control Panel / System / Memory or
viewed programatically) does not decrease at all.
Now assuming there are no memory leaks in this library, I have to
assume that the heap for my process has grown by 4MB and although the
memory is correctly 'deleted', the heap does not shrink (or at least
not immediately). Is this normal? I question that it is because if I
do something like:
char * arr = new char[4*1024*1024];
delete[] arr;
I see the memory usage go up by 4 MB and then back down right away. So
why does it reduce the heap size in one case but not in another? Is it
because the 4MB array is all contiguous memory and thus much easier to
get rid of?
I only ask because the customer is questioning why my app is taking
all this memory when it really only needs to use it during startup
while reading in this XML file.
Thanks,
Ryan
-
Re: Windows CE Heap Allocation
I can't say whether the actual numbers that you're seeing are normal or not,
but, yes, the heap doesn't shrink instantly when you free an object. In the
particular test case you're showing there, a single allocation of a large
memory chunk might very well be thrown into a separate heap or its own
LocalAlloc() block, which would be freed when you release it. You could
build a fair test by allocating blocks of various sizes using new and then
going through the list and freeing them in random order. If that memory is
all freed when you release it, I'd say that there's something wrong with
your XML library, but I wouldn't expect that to happen. As long as you're
not getting out-of-memory errors, I wouldn't even call this a problem.
Paul T.
wrote in message
news:1178995147.812277.96600@e65g2000hsc.googlegro ups.com...
> I'm using an XML library (http://sourceforge.net/projects/tinyxml/) on
> Windows CE 4.2, and after loading a 670KB XML file into memory with
> it, it decreases my available memory by about 4MB. Once I delete the
> document object (which frees all nodes / elements / etc.), my
> available memory (displayed by the Control Panel / System / Memory or
> viewed programatically) does not decrease at all.
>
> Now assuming there are no memory leaks in this library, I have to
> assume that the heap for my process has grown by 4MB and although the
> memory is correctly 'deleted', the heap does not shrink (or at least
> not immediately). Is this normal? I question that it is because if I
> do something like:
>
> char * arr = new char[4*1024*1024];
> delete[] arr;
>
> I see the memory usage go up by 4 MB and then back down right away. So
> why does it reduce the heap size in one case but not in another? Is it
> because the 4MB array is all contiguous memory and thus much easier to
> get rid of?
>
> I only ask because the customer is questioning why my app is taking
> all this memory when it really only needs to use it during startup
> while reading in this XML file.
>
> Thanks,
> Ryan
>
-
Re: Windows CE Heap Allocation
Thanks for the reply. I agree that it isn't a problem, but when you
tell a customer you're only using X memory but they use the CE memory
utility and say "oh, it looks like you're using more than you said..."
I had to be sure that what I thought was happening was at least
probable. Thanks again - and I'll give your test idea a try just for
fun.
- Ryan
On May 14, 11:05 am, "Paul G. Tobey [eMVP]"
no instrument no spam DOT com> wrote:
> I can't say whether the actual numbers that you're seeing are normal or not,
> but, yes, the heap doesn't shrink instantly when you free an object. In the
> particular test case you're showing there, a single allocation of a large
> memory chunk might very well be thrown into a separate heap or its own
> LocalAlloc() block, which would be freed when you release it. You could
> build a fair test by allocating blocks of various sizes using new and then
> going through the list and freeing them in random order. If that memory is
> all freed when you release it, I'd say that there's something wrong with
> your XML library, but I wouldn't expect that to happen. As long as you're
> not getting out-of-memory errors, I wouldn't even call this a problem.