Search⌘ K

Memory Block Attributes

Explore how to use memory block attributes in D programming to control garbage collection behavior. Understand flags like FINALIZE, NO_SCAN, and NO_MOVE that optimize memory scanning, object finalization, and allocation. This lesson helps you manage memory safely and extend memory areas dynamically in your D programs.

We'll cover the following...

The concepts and the steps of a GC algorithm can be configured to some degree for each memory block by enum BlkAttr. BlkAttr is an optional parameter of GC.calloc and other allocation functions. It consists of the following values:

  • NONE: The value zero; specifies no attribute

  • FINALIZE: Specifies that the objects that live in the memory block should be finalized

Normally, the GC assumes that the lifetimes of objects that live on explicitly- allocated memory locations are under the control of the programmer; it does not finalize objects on such memory areas. GC.BlkAttr.FINALIZE is for requesting the GC to execute the destructors of objects:

D
Class * buffer =
cast(Class*)GC.calloc(
__traits(classInstanceSize, Class) * 10,
GC.BlkAttr.FINALIZE);

Note: FINALIZE ...