Files
vystem/docs/shelter/std/malloc.md
2026-03-31 22:15:00 +02:00

1023 B

Heap memory allocations

The Shelter standard library provide a single API for memory allocations on the heap. The heap is only initialized at the end of the memory subsystem and can't be used before. It's not adapted for memory mapped I/O or big buffers allocations (larger than one hundrer pages). The heap internal documentation can be found inside the memory subsystem documentation.

The memory allocations API provide the two following functions (defined inside shelter/lib/include/std/malloc.h and implemented inside shelter/lib/src/std/malloc.c):

  • void* sh_malloc(sh_uint64 size): allocate size amount of bytes. Return SH_NULLPTR if an error occured. The heap internal will trigger a heap crash (essentially a while (SH_TRUE) loop) to prevent any further damage if something very bad happen.
  • void sh_free(void *ptr): free the memory allocated at ptr. The heap internal will trigger a heap crash (essentially a while (SH_TRUE) loop) to prevent any further damage if something very bad happen.