Modules

rpmalloc

moduleSource

Available on macOS, Linux, Windows, Wasm

#import "rpmalloc";

Module parameters#

HEAP_ARRAY_SIZE := 47
The size of the table of heaps that threads share.
DEFAULT_SPAN_MAP_COUNT := 64
How many spans are mapped at a time.
GLOBAL_CACHE_MULTIPLIER := 8
How many times larger the global cache is than a thread cache.
ENABLE_THREAD_CACHE := true
Keeps freed spans in a cache for each thread.
ENABLE_GLOBAL_CACHE := true
Keeps freed spans in a cache that threads share. Needs the thread cache.
ENABLE_STATISTICS := true
Counts allocations and mapped memory for the statistics procedures.
ENABLE_ASSERTS := true
Checks the allocator's internal invariants.
ENABLE_VALIDATE_ARGS := true
Checks the arguments of its procedures.
LINUX_FREE_ADVICE: enum { DONTNEED; FREE; } = .DONTNEED
The advice given to Linux when pages are freed.
CONFIGURABLE := false
Lets the allocator be configured when it is initialized.
ENABLE_ADAPTIVE_THREAD_CACHE := false
Sizes each thread's cache from how the thread allocates. Needs the thread cache.
LINUX_HUGE_PAGES := false
Asks Linux for transparent huge pages.
USE_RAW := false
Binds the C interface with size_t and the C types as the header writes them, not s64.
DISABLE_UNMAP := false
Never returns memory to the OS. Needs the global and unlimited caches.
ENABLE_UNLIMITED_CACHE := false
Lets the caches grow without a limit. Needs the global cache.

Procedures#

Wrappers#

rpmalloc2 overloadsSource
(size: s64) -> *void
(size: size_t) -> *void
rprealloc2 overloadsSource
(ptr: *void, size: s64) -> *void
(ptr: *void, size: size_t) -> *void
(alignment: s64, size: s64) -> *void
(alignment: size_t, size: size_t) -> *void

Allocator#

Types#

:: struct
memory_map: #type (size: s64, offset: *s64) -> *void
memory_unmap: #type (address: *void, size: s64, offset: s64, release: s64) -> ()
error_callback: #type (message: string, location: Source_Code_Location) -> ()
map_fail_callback: #type (size: s64) -> s32
page_size: s64
span_size: s64
span_map_count: s64
enable_huge_pages: bool
page_name: string
huge_page_name: string
:: struct
sizecache: s64
spancache: s64
thread_to_global: s64
global_to_thread: s64
span_use: [64] struct { current: s64; peak: s64; to_global: s64; from_global: s64; to_cache: s64; from_cache: s64; to_reserved: s64; from_reserved: s64; map_calls: s64; }
size_use: [128] struct { alloc_current: s64; alloc_peak: s64; alloc_total: s64; free_total: s64; spans_to_cache: s64; spans_from_cache: s64; spans_from_reserved: s64; map_calls: s64; }

Constants#