Could someone calrify reserving and collecting memory via the Garbabe Collector ?
wjoe
invalid at example.com
Thu Aug 6 21:59:55 UTC 2020
On Thursday, 6 August 2020 at 17:18:12 UTC, rikki cattermole
wrote:
> On 07/08/2020 5:12 AM, wjoe wrote:
>> There's core.memory.GC.reserve which requests memory from the
>> OS. Basically pre-allocating memory for the GC heap.
>>
>> Is the GC heap shared among all threads ?
>
> That is up to the GC implementation.
That means to be able to reason about it, I need to read the
implementation and should it change, my reasoning might be wrong
all of a sudden.
>> And is it correct that even if I call GC.disable, the GC may
>> still start a collection run if, for instance, there's an
>> allocation but no free memory on the GC heap ?
>
> "Disables automatic garbage collections performed to minimize
> the process footprint. Collections may continue to occur in
> instances where the implementation deems necessary for correct
> program behavior, such as during an out of memory condition.
> This function is reentrant, but enable must be called once for
> each call to disable."
>
> https://dlang.org/phobos/core_memory.html#.GC.disable
>
> So yes.
>
> Note, out of memory is related to the process, rather than GC
> internals (it does play a part, but lets just go with process).
I've read that but wasn't sure.
But the process isn't necessarily out of memory when the GC heap
is completely in use.
Instead of starting a collection, the GC could for instance
request more memory from the OS.
Thanks for your reply.
More information about the Digitalmars-d-learn
mailing list