IndexZone Memoryasmjit::Zone

asmjit::Zone Class Reference [¶]

Inheritance diagram for asmjit::Zone:
asmjit::ZoneTmp< N >

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.

Public Members

Members

Member Functions

Construction & Destruction
Accessors
Utilities
Allocation

Zone::Zone(
size_t minimumBlockSize
)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.

Zone::Zone(
size_t minimumBlockSize,
const Support::Temporary& temporary
)noexcept[2/4][¶]

Creates a new Zone with a first block pointing to a temporary memory.

Zone::Zone(
size_t minimumBlockSize,
const Support::Temporary* temporary
)noexcept[3/4][¶]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Zone::Zone(
Zone&& other
)noexcept[4/4][¶]

Moves an existing Zone.

Note
You cannot move an existing ZoneTmp as it uses embedded storage. Attempting to move ZoneTmp would cause an undefined behavior (covered by assertions in debug mode).

Zone::~Zone()noexcept[¶]

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).

void Zone::reset()noexcept[¶]

Resets the Zone invalidating all blocks allocated.

See Globals::ResetPolicy for more details.

size_t Zone::minimumBlockSize() constnoexcept[¶]

Returns a minimum block size.

size_t Zone::maximumBlockSize() constnoexcept[¶]

Returns a maximum block size.

uint8_t Zone::hasStaticBlock() constnoexcept[¶]

Tests whether this Zone is actually a ZoneTmp that uses temporary memory.

size_t Zone::remainingSize() constnoexcept[¶]

Returns remaining size of the current block.

template<typename T = uint8_t>
T* Zone::ptr()noexcept[¶]

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.

template<typename T = uint8_t>
T* Zone::end()noexcept[¶]

Returns the end of the current zone block, only useful if you use ptr().

template<typename T>
void Zone::setPtr(
T* ptr
)noexcept[¶]

Sets the current zone pointer to ptr (must be within the current block).

template<typename T>
void Zone::setEnd(
T* end
)noexcept[¶]

Sets the end zone pointer to end (must be within the current block).

void Zone::align(
size_t alignment
)noexcept[¶]

Aligns the current pointer to alignment.

template<typename T = void>
T* Zone::alloc(
size_t size
)noexcept[¶]

Allocates the requested memory specified by size and optionally casts the returned value to T*.

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:

using namespace asmjit;
class Object { ... };
// Create Zone with default block size of 65536 bytes (the maximum size per alloc() would be slightly less).
Zone zone(65536);
// Create your objects using zone object allocating, for example:
Object* obj = static_cast<Object*>( zone.alloc(sizeof(Object)) );
if (!obj) {
// Handle out of memory error.
}
// Placement `new` and `delete` operators can be used to instantiate it.
new(obj) Object();
// ... lifetime of your objects ...
// To destroy the instance (if required).
obj->~Object();
// Reset or destroy `Zone`.
zone.reset();

void* Zone::allocZeroed(
size_t size
)noexcept[¶]

Allocates size bytes of zeroed memory. See alloc() for more details.

template<typename T>
T* Zone::newT()noexcept[1/2][¶]

Like new(std::nothrow) T(...), but allocated by Zone.

template<typename T, typename... Args>
T* Zone::newT(
Args&&... args
)noexcept[2/2][¶]

Like new(std::nothrow) T(...), but allocated by Zone.

void* Zone::dup(
const void* data,
size_t size,
bool nullTerminate = false
)noexcept[¶]

Helper to duplicate data.

char* Zone::sformat(
const char* str, ...
)noexcept[¶]

Helper to duplicate a formatted string, maximum size is 256 bytes.

uint8_t* Zone::_ptr[¶]

Pointer in the current block.

uint8_t* Zone::_end[¶]

End of the current block.

Block* Zone::_block[¶]

Current block.

Block* Zone::_first[¶]

First block (single-linked list).

uint8_t Zone::_currentBlockSizeShift[¶]

Current block size shift - reverted to _minimumBlockSizeShift every time the Zone is reset(ResetPolicy::kHard).

uint8_t Zone::_minimumBlockSizeShift[¶]

Minimum log2(blockSize) to allocate.

uint8_t Zone::_maximumBlockSizeShift[¶]

Maximum log2(blockSize) to allocate.

uint8_t Zone::_hasStaticBlock[¶]

True when the Zone has a static block (static blocks are used by ZoneTmp).

uint32_t Zone::_reserved[¶]

Reserved for future use, must be zero.