AsmJit
Low-Latency Machine Code Generation
Zone memory.
Zone is an incremental memory allocator that allocates memory by simply incrementing a pointer. It allocates blocks of memory by using C's malloc()
, but divides these blocks into smaller segments requested by calling Zone::alloc()
and friends.
Zone has no function to release the allocated memory. It has to be released all at once by calling reset()
. If you need a more friendly allocator that also supports release()
, consider using Zone
with ZoneAllocator
.
1
)explicitnoexcept[1/4]◆ Creates a new Zone.
The blockSize
parameter describes the default size of the block. If the size
parameter passed to alloc()
is greater than the default size Zone
will allocate and use a larger block, but it will not change the default blockSize
.
It's not required, but it's good practice to set blockSize
to a reasonable value that depends on the usage of Zone
. Greater block sizes are generally safer and perform better than unreasonably low block sizes.
Creates a new Zone with a first block pointing to a temporary
memory.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Moves an existing Zone
.
ZoneTmp
as it uses embedded storage. Attempting to move ZoneTmp
would result in assertion failure in debug mode and undefined behavior in release mode. Destroys the Zone
instance.
This will destroy the Zone
instance and release all blocks of memory allocated by it. It performs implicit reset(ResetPolicy::kHard)
.
ResetPolicy::kSoft
)noexcept◆ Resets the Zone
invalidating all blocks allocated.
See Globals::ResetPolicy
for more details.
Tests whether this Zone
is actually a ZoneTmp
that uses temporary memory.
Returns the default block size.
Returns the default block alignment.
Returns remaining size of the current block.
Returns the current zone cursor (dangerous).
This is a function that can be used to get exclusive access to the current block's memory buffer.
Returns the end of the current zone block, only useful if you use ptr()
.
Sets the current zone pointer to ptr
(must be within the current block).
Sets the end zone pointer to end
(must be within the current block).
Aligns the current pointer to alignment
.
Ensures the remaining size is at least equal or greater than size
.
align()
before calling ensure()
. Allocates the requested memory specified by size
.
Pointer returned is valid until the Zone
instance is destroyed or reset by calling reset()
. If you plan to make an instance of C++ from the given pointer use placement new
and delete
operators:
Allocates the requested memory specified by size
and alignment
.
Allocates the requested memory specified by size
without doing any checks.
Can only be called if remainingSize()
returns size at least equal to size
.
Allocates the requested memory specified by size
and alignment
without doing any checks.
Performs the same operation as Zone::allocNoCheck(size)
with alignment
applied.
1
)noexcept◆ Allocates size
bytes of zeroed memory. See alloc()
for more details.
sizeof(T)
, size_t alignment = alignof(T)
)noexcept◆ Like alloc()
, but the return pointer is casted to T*
.
sizeof(T)
, size_t alignment = alignof(T)
)noexcept◆ Like allocNoCheck()
, but the return pointer is casted to T*
.
sizeof(T)
, size_t alignment = alignof(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
.
false
)noexcept◆ Helper to duplicate data.
false
)noexcept◆ Helper to duplicate data.
Helper to duplicate a formatted string, maximum size is 256 bytes.