Different allocation types

How memory is allocated by a container depends entirely on the type of container, and as a result, an allocator must be able to support different allocation types, such as the following:

  • All allocations by an allocator must be contiguous in memory. There is no requirement for one allocation to be contiguous in memory with another allocation, but each individual allocation must be contiguous.
  • An allocator must be able to allocate more than one element in a single allocation. This can sometimes be problematic depending on the allocator.

To explore these properties, let's use the following example:

template<typename T>class myallocator{public:    using value_type = T;    using pointer = T *; using size_type = std::size_t; ...

Get Hands-On System Programming with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.