C++ Standard Template Library (STL) containers are a simple, as well as effective, way of managing resources. One huge benefit of containers is that they can manage (almost) any type of data. When dealing with system programming, though, we may need to provide an alternative way of managing memory for our container. Allocators are exactly this: they provide a custom implementation to a container.
Dealing with allocators hands-on
How to do it...
In this recipe, you'll learn to implement your own custom allocator (based on mmap, in this case) to provide to a standard library container (std::vector):
- Let's create an empty allocator template first:
template<typename T>
class mmap_allocator
{
public...