(gcc returns mem) Re: When is it time for a 1.0 feature freeze?
Serg Kovrov
kovrov at no.spam
Tue Sep 5 08:36:25 PDT 2006
* Bruno Medeiros:
> Walter Bright wrote:
>> What your program is doing is allocating a gigantic chunk. It is a
>> reasonable thing for new() to have a fork in it, and for gigantic
>> chunks allocate/free them by calling the OS directly and not
>> attempting to manage it. Thus you would see the behavior you see.
>>
>> Try allocating a large number of small chunks, and free them.
>
> Hum, I modified the program and tried 4 more tests:
>
> Allocating 10000 (sequential) chunks of size 10000 bytes. Free them all.
> -> All the 100Mb of memory is returned to the OS.
>
> Allocating 100000 (sequential) chunks of size 1000 bytes. Free them all.
> -> All the 100Mb of memory is returned to the OS.
>
> Allocating 10000 (sequential) chunks of size 10000 bytes. Free only half
> of them, the even numbered ones, so that the total freed memory is not
> contiguous.
> -> Of the 50Mb memory free'd, about 30Mb of memory is returned to the
> OS. Expected due to page segmentantion/rounding.
>
> Allocating 100000 (sequential) chunks of size 1000 bytes. Again free
> only the even numbered ones.
> -> 50Mb memory is free'd, but no memory is returned to the OS. Expected
> due to page segmentantion/rounding.
>
> So it seems glibc does its best, it returns any page if it is all free.
> (hum, and I'm curious to what the results in VC++ are, if anyone tries
> it, do post the results)
I can't be sure, but it's possible that Microsoft runtime library
'delete' implementation calls _heapmin()
[http://msdn2.microsoft.com/en-us/library/fc7etheh.aspx] for that
purpose. I red about it some time ago in a post on
comp.os.ms-windows.programmer. The actual discussion was about delete
not returning memory to OS =) I think it really depends on some other
factors. The point was that 'delete'(or 'free') *could* return memory to
OS, but not guaranteed.
Phobos' GC has a stub f-n std.gc.minimize(), which probably intended for
same purpose. I hope Walter could provide an update on it real purpose
and implementation plans.
--
serg.
More information about the Digitalmars-d
mailing list