AsmJit
Low-Latency Machine Code Generation
Zone-based memory allocator that uses an existing Zone
and provides a release()
functionality on top of it.
It uses Zone
only for chunks that can be pooled, and uses libc malloc()
for chunks that are large.
The advantage of ZoneAllocator is that it can allocate small chunks of memory really fast, and these chunks, when released, will be reused by consecutive calls to alloc()
. Also, since ZoneAllocator uses Zone
, you can turn any Zone
into a ZoneAllocator
, and use it in your Pass
when necessary.
ZoneAllocator is used by AsmJit containers to make containers having only few elements fast (and lightweight) and to allow them to grow and use dynamic blocks when require more storage.
Creates a new ZoneAllocator
.
init()
it. Creates a new ZoneAllocator
initialized to use zone
.
Destroys the ZoneAllocator
.
Tests whether the ZoneAllocator
is initialized (i.e. has Zone
).
Convenience function to initialize the ZoneAllocator
with zone
.
It's the same as calling reset(zone)
.
nullptr
)noexcept◆ Resets this ZoneAllocator
and also forget about the current Zone
which is attached (if any).
Reset optionally attaches a new zone
passed, or keeps the ZoneAllocator
in an uninitialized state, if zone
is null.
Returns the assigned Zone
of this allocator or null if this ZoneAllocator
is not initialized.
Allocates size
bytes of memory, ideally from an available pool.
size
can't be zero, it will assert in debug mode in such case. Like alloc(size)
, but provides a second argument allocatedSize
that provides a way to know how big the block returned actually is.
This is useful for containers to prevent growing too early.
sizeof(T)
)noexcept◆ Like alloc()
, but the return pointer is casted to T*
.
Like alloc(size)
, but returns zeroed memory.
Like alloc(size, allocatedSize)
, but returns zeroed memory.
sizeof(T)
)noexcept◆ Like allocZeroed()
, but the return pointer is casted to T*
.
Like new(std::nothrow) T(...)
, but allocated by Zone
.
Like new(std::nothrow) T(...)
, but allocated by Zone
.
Releases the memory previously allocated by alloc()
.
The size
argument has to be the same as used to call alloc()
or allocatedSize
returned by alloc()
.
Zone used to allocate memory that fits into slots.
Indexed slots containing released memory.
Dynamic blocks for larger allocations (no slots).