Skip to content

dmemory.h

RedstoneShell edited this page Oct 11, 2026 · 1 revision

DMEMORY_H

Linking by #include <dmemory.h>, compiling by adding dmemory.o in linker.

dh_heap_block

Structure that used for creation Heap in memory.

typedef struct dh_heap_block {
    u32  pattern;                       /* DHBL_PATTERN */
    u32  flags;                         /* DHEAP_BLOCK_* */
    char source[DHEAP_SOURCE_MAX];      /* task_name of creator */
    u64  size;                          /* real used bytes */
    u64  capacity;                      /* DHEAP_BLOCK_DATA_SIZE */
    u64  alloc_head;                    /* bump pointer in data[] */
    u64  last_scan_tick;                /* LHGC: where scan */
    u64  last_hash;                     /* LHGC: hash of last scan */
    u64  generation;                    /* Heap ID */
    u32  same_count;                    /* LHGC: Count of same scans */
    u32  _pad;
    u8   data[DHEAP_BLOCK_DATA_SIZE];   /* payload, zero-filled at creation */
} dh_heap_block_t;

dh_heap_header

Structure at start of Heap Memory Block, used by LHGC for calculations about Heaps, pointer where create new Heap and etc.

typedef struct dh_heap_header {
    u32  pattern;                       /* DHMB_PATTERN */
    u32  version;                       /* DHMB_VERSION */
    u64  size;                          /* Std region size */
    u32  blocks_count;                  /* Used blocks */
    u32  block_step;                    /* = sizeof(dh_heap_block_t) */
    u32  total_slots;                   /* Total slots in region */
    u32  free_slots;                    /* Free slots */
    u64  scan_tick;                     /* LHGC Last scan */
    u64  gc_runs;                       /* LHGC scan count */
    u64  gc_reclaimed;                  /* Count of killed blocks by LHGC */
    u8   _reserved[64];
} dh_heap_header_t;

dh_heap (D_HEAP_POINTER)

Used as pointer at heap, returns by DCreateHeap and used for terminating heap by DCloseHeap.

typedef struct dh_heap {
    u32  slot;                          /* Slot idx in region*/
    u32  magic;                         /* 0xDEADBEEF - for validation */
    u64  generation;                    /* ++ at every slot reusage */
} dh_heap_t;

DCreateHeap(const *source: char): D_HEAP_POINTER|0

Creates a new Heap in Heap Memory Block, in source you receive name of heap. Returns a pointer at heap, Please, save this pointer for correctly destroying heap, or LHGC makes this automatically for you. WARNING: If you try to create new heap if LHGC in this moment compacting Heaps, returns 0 and Heap don't create.

DWriteHeap(heap: D_HEAP_POINTER, offset: u64, const data: void*, size: u64): dstatus_t(u64)

Write data to heap. heap is pointer at heap created by DCreateHeap, offset is offset in heap memory (256 MB), data is everything that you need to write at offset, size is size of data that write in heap. Returns DEPRESSURE_STATUS_OK if success, DEPRESSURE_NULL_DATA if data is null or heap pointer, DEPRESSURE_HEAP_WITHOUT_FREE_SPACE if offset pointer out of bounds of Heap Memory, DEPRESSURE_NOT_INITIALIZED if you try to write data in heap, before Heap Memory Block is initialized.

DReadHeap(heap: D_HEAP_POINTER, offset: u64, out: void*, size: u64): dstatus_t(u64)

Read data from heap. heap is pointer at heap created by DCreateHeap, offset is offset in heap memory (256 MB), data is buffer where writes data from memory, size is size of data that write in buffer. Returns DEPRESSURE_STATUS_OK if success, DEPRESSURE_NULL_DATA if out is null or heap pointer, DEPRESSURE_OUT_OF_RANGE if offset pointer out of bounds of Heap Memory, DEPRESSURE_NOT_INITIALIZED if you try to read data from heap, before Heap Memory Block is initialized.

DCloseHeap(heap: D_HEAP_POINTER): dstatus_t(u64)

Destroy heap by she pointer. Returns DEPRESSURE_STATUS_OK if success, DEPRESSURE_NULL_DATA if heap pointer is null, DEPRESSURE_NOT_INITIALIZED if you try to destroy heap, before Heap Memory Block is initialized.

dmemory_total(void): u64

Returns 16MB in bytes.

dmemory_used(void): u64

Returns total allocated bytes in Heap Memory Block.

dmemory_heap_count(void): u32

Returns count of Heaps.

dmemory_free_slots(void): u32

Returns count of free slots for new Heaps.

dmemory_dump(void (*log)(const char *))

Send every information about Heap Memory Block and Heap Blocks in memory to function received in argument.

Clone this wiki locally