Class Allocator

Class Documentation

class Allocator

Provides a unified interface to allocate and free data.

An Allocator encapsulates all the details of how and where allocations will be made, and can also be used to introspect the memory resource. Allocator objects do not return typed allocations, so the pointer returned from the allocate method must be cast to the relevant type.

See

TypedAllocator

Public Functions

void *allocate(std::size_t bytes)

Allocate bytes of memory.

The memory will be allocated as determined by the AllocationStrategy used by this Allocator. Note that this method does not guarantee new memory pages being requested from the underlying memory system, as the associated AllocationStrategy could have already allocated sufficient memory, or re-use existing allocations that were not returned to the system.

Return

Pointer to start of the allocation.

Parameters
  • bytes: Number of bytes to allocate (>= 0)

void deallocate(void *ptr)

Free the memory at ptr.

This method will throw an umpire::Exception if ptr was not allocated using this Allocator. If you need to deallocate memory allocated by an unknown object, use the ResourceManager::deallocate method.

Parameters
  • ptr: Pointer to free (!nullptr)

void release()

Release any and all unused memory held by this Allocator.

std::size_t getSize(void *ptr) const

Return number of bytes allocated for allocation.

Return

number of bytes allocated for ptr

Parameters
  • ptr: Pointer to allocation in question

std::size_t getHighWatermark() const

Return the memory high watermark for this Allocator.

This is the largest amount of memory allocated by this Allocator. Note that this may be larger than the largest value returned by getCurrentSize.

Return

Memory high watermark.

std::size_t getCurrentSize() const

Return the current size of this Allocator.

This is sum of the sizes of all the tracked allocations. Note that this doesn’t ever have to be equal to getHighWatermark.

Return

current size of Allocator.

std::size_t getActualSize() const

Return the actual size of this Allocator.

For non-pool allocators, this will be the same as getCurrentSize().

For pools, this is the total amount of memory allocated for blocks managed by the pool.

Return

actual size of Allocator.

const std::string &getName() const

Get the name of this Allocator.

Allocators are uniquely named, and the name of the Allocator can be used to retrieve the same Allocator from the ResourceManager at a later time.

See

ResourceManager::getAllocator

Return

name of Allocator.

int getId() const

Get the integer ID of this Allocator.

Allocators are uniquely identified, and the ID of the Allocator can be used to retrieve the same Allocator from the ResourceManager at a later time.

See

ResourceManager::getAllocator

Return

integer id of Allocator.

strategy::AllocationStrategy *getAllocationStrategy()

Get the AllocationStrategy object used by this Allocator.

Return

Pointer to the AllocationStrategy.

Platform getPlatform()

Get the Platform object appropriate for this Allocator.

Return

Platform for this Allocator.

Allocator()

Friends

friend umpire::Allocator::::AllocatorTest
std::ostream &operator<<(std::ostream &os, const Allocator &allocator)