Repository navigation
dmemory.h
Linking by #include <dmemory.h>, compiling by adding dmemory.o in linker.
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;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;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;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.
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.
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.
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.
Returns 16MB in bytes.
Returns total allocated bytes in Heap Memory Block.
Returns count of Heaps.
Returns count of free slots for new Heaps.
Send every information about Heap Memory Block and Heap Blocks in memory to function received in argument.