digitalmars.D.learn - Could someone calrify reserving and collecting memory via the Garbabe
- wjoe (8/8) Aug 06 2020 There's core.memory.GC.reserve which requests memory from the OS.
- rikki cattermole (11/18) Aug 06 2020 "Disables automatic garbage collections performed to minimize the
- wjoe (11/30) Aug 06 2020 That means to be able to reason about it, I need to read the
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 ?
Aug 06 2020
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).
Aug 06 2020
On Thursday, 6 August 2020 at 17:18:12 UTC, rikki cattermole wrote:On 07/08/2020 5:12 AM, wjoe wrote: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.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.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.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).
Aug 06 2020