Muokkaa

Jaa


freelist Class

Manages a list of memory blocks.

Syntax

template <std::size_t Sz, class Max>
class freelist : public Max

Parameters

Sz
The number of elements in the array to be allocated.

Max
The max class representing the maximum number of elements to be stored in the free list. The max class can be max_none, max_unbounded, max_fixed_size, or max_variable_size.

Remarks

This class template manages a list of memory blocks of size Sz with the maximum length of the list determined by the max class passed in Max.

Constructors

Constructor Description
freelist Constructs an object of type freelist.

Member functions

Member function Description
pop Removes the first memory block from the free list.
push Adds a memory block to the list.

Requirements

Header: <allocators>

Namespace: stdext

freelist::freelist

Constructs an object of type freelist.

freelist();

Remarks

freelist::pop

Removes the first memory block from the free list.

void *pop();

Return Value

Returns a pointer to the memory block removed from the list.

Remarks

The member function returns NULL if the list is empty. Otherwise, it removes the first memory block from the list.

freelist::push

Adds a memory block to the list.

bool push(void* ptr);

Parameters

ptr
A pointer to the memory block to be added to the free list.

Return Value

true if the full function of the max class returns false; otherwise, the push function returns false.

Remarks

If the full function of the max class returns false, this member function adds the memory block pointed to by ptr to the head of the list.

See also

<allocators>