asmjit::ZoneAllocator Class Reference

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.

Public Members

Members

Member Functions

Construction & Destruction
Accessors
Allocation

Constructor & Destructor Documentation

ZoneAllocator::ZoneAllocator()noexcept[1/2]◆ 

Creates a new ZoneAllocator.

Note
To use it, you must first init() it.

ZoneAllocator::ZoneAllocator(Zone* zone)explicitnoexcept[2/2]◆ 

Creates a new ZoneAllocator initialized to use zone.

ZoneAllocator::~ZoneAllocator()noexcept◆ 

Destroys the ZoneAllocator.

Member Function Documentation

bool ZoneAllocator::isInitialized() constnoexcept◆ 

Tests whether the ZoneAllocator is initialized (i.e. has Zone).

void ZoneAllocator::init(Zone* zone)noexcept◆ 

Convenience function to initialize the ZoneAllocator with zone.

It's the same as calling reset(zone).

void ZoneAllocator::reset(Zone* 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.

Zone* ZoneAllocator::zone() constnoexcept◆ 

Returns the assigned Zone of this allocator or null if this ZoneAllocator is not initialized.

void* ZoneAllocator::alloc(size_t size)noexcept[1/2]◆ 

Allocates size bytes of memory, ideally from an available pool.

Note
size can't be zero, it will assert in debug mode in such case.

void* ZoneAllocator::alloc(size_t size, size_t& allocatedSize)noexcept[2/2]◆ 

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.

template<typename T>
T* ZoneAllocator::allocT(size_t size = sizeof(T))noexcept◆ 

Like alloc(), but the return pointer is casted to T*.

void* ZoneAllocator::allocZeroed(size_t size)noexcept[1/2]◆ 

Like alloc(size), but returns zeroed memory.

void* ZoneAllocator::allocZeroed(size_t size, size_t& allocatedSize)noexcept[2/2]◆ 

Like alloc(size, allocatedSize), but returns zeroed memory.

template<typename T>
T* ZoneAllocator::allocZeroedT(size_t size = sizeof(T))noexcept◆ 

Like allocZeroed(), but the return pointer is casted to T*.

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

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

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

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

void ZoneAllocator::release(void* p, size_t size)noexcept◆ 

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

Member Data Documentation

Zone* ZoneAllocator::_zone {}◆ 

Zone used to allocate memory that fits into slots.

Slot* ZoneAllocator::_slots[kLoCount+kHiCount] {}◆ 

Indexed slots containing released memory.

DynamicBlock* ZoneAllocator::_dynamicBlocks {}◆ 

Dynamic blocks for larger allocations (no slots).