Thread overview | |||||
---|---|---|---|---|---|
|
August 06, 2020 Could someone calrify reserving and collecting memory via the Garbabe Collector ? | ||||
---|---|---|---|---|
| ||||
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 ? E.g what happens if I GC.reserve(4.MiB) ? Is it 4 MiB in total or per thread ? 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 ? |
August 07, 2020 Re: Could someone calrify reserving and collecting memory via the Garbabe Collector ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to wjoe | 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. > 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). |
August 06, 2020 Re: Could someone calrify reserving and collecting memory via the Garbabe Collector ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | 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. |
Copyright © 1999-2021 by the D Language Foundation