Template Class stl_allocator

Nested Relationships

Nested Types

Template Parameter Order

  1. typename T

Class Documentation

template<typename T>
class stl_allocator

stl_allocator is STL-compatible allocator used to provide fixed block allocations.

The default allocator for the STL is the global heap. The stl_allocator is custom allocator where xmalloc/xfree is used to obtain and release memory.

Public Types

typedef size_t size_type
typedef ptrdiff_t difference_type
typedef T *pointer
typedef const T *const_pointer
typedef T &reference
typedef const T &const_reference
typedef T value_type

Public Functions

inline stl_allocator()

Constructor.

inline ~stl_allocator()

Destructor.

template<class U>
inline stl_allocator(const stl_allocator<U>&)

Copy constructor.

inline pointer address(reference x) const

Return reference address.

Returns

Pointer to T memory.

inline const_pointer address(const_reference x) const

Return reference address.

Returns

Const pointer to T memory.

inline size_type max_size() const

Get the maximum size of memory.

Returns

Max memory size in bytes.

inline pointer allocate(size_type n, stl_allocator<void>::const_pointer hint = nullptr)

Allocates a fixed block of memory

Parameters
  • n[in] - size of memory to allocate in bytes

  • hint[in]

Returns

Pointer to the allocated memory.

inline void deallocate(pointer p, size_type n)

Deallocate a previously allocated fixed memory block.

Parameters
  • p[in] - pointer to the memory block

  • n[in] - size of memory in bytes

inline void construct(pointer p, const T &val)

Constructs a new instance.

Parameters
  • p[in] - pointer to the memory where the instance is constructed using placement new.

  • val[in] - instance of object to copy construct.

inline void construct(pointer p)

Create a new object instance using placement new.

Parameters

p[in] - pointer to the memory where the instance is constructed using placement new.

inline void destroy(pointer p)

Destroys an instance. Objects created with placement new must explicitly call the destructor.

Parameters

p[in] - pointer to object instance.

template<class U>
struct rebind

Public Types

typedef stl_allocator<U> other