Skip to content

Allocator concept

cppreference C++ named requirements: Allocator

Encapsulates strategies for access/addressing, allocation/deallocation and construction/destruction of objects.

NOTE:

一、典型的policy-based design,std::allocator 是它的default implementation:

The std::allocator class template is the default Allocator used by all standard library containers if no user-specified allocator is provided.

std::vector

template<
    class T,
    class Allocator = std::allocator<T>
> class vector;

Fancy pointers

NOTE:

1、下面关于fancy pointer的介绍值得借鉴

a、raw pointer用于access virtual address space

b、fancy pointer用于access" objects allocated in address spaces that differ from the homogeneous(同质的) virtual address space "

2、关于"memory mapped files",参见:

a、wikipedia Memory-mapped file

b、工程Linux-OS,其中对它进行了介绍

When the member type pointer is not a raw pointer type, it is commonly referred to as a "fancy pointer". Such pointers were introduced to support segmented memory architectures and are used today to access objects allocated in address spaces that differ from the homogeneous(同质的) virtual address space that is accessed by raw pointers. An example of a fancy pointer is the mapping address-independent pointer boost::interprocess::offset_ptr, which makes it possible to allocate node-based data structures such as std::set in shared memory and memory mapped files mapped in different addresses in every process.

Examples

NOTE:

1、这个例子演示了如下custom allocator