Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Allocation Module

This module binds together classes providing different ways to perform memory allocation. This kind of class is usually passed to any container class performing automatic memory allocation. More...

Classes

class  GCManager
 
class  BlockAllocator< T >
 
class  BadAlloc
 
class  DefaultAllocator
 
class  GroupedGC
 
class  ListGC
 
class  Temp
 
class  class
 
class  SimpleGC
 
class  StackAllocator
 

Detailed Description

This module binds together classes providing different ways to perform memory allocation. This kind of class is usually passed to any container class performing automatic memory allocation.

The chosen allocator is usually passed as a template parameter to the collection type and as a parameter to the collection constructor.

An allocator class must implement the concept elm::concept::Allocator.

A collection supporting allocator matches the concept below:

template <class A>
class CollectionWithAllocation {
public:
CollectionWithAllocation(A& allocator = A::DEFAULT);
};

An easy use of custom allocator is the overload of new and delete operators of a class to let passing the allocator as a parameter. The code below gives an examples:

class MyClass {
public:
// usual constructors, methods and attributes
inline void *operator new(std::size_t size, Allocator& alloc) { return alloc.allocate(size); }
inline void operator delete(void *p, std::size_t size) { alloc.free(p); }

Then, you can create and delete the object with the following code:

Allocator custom_alloc;
MyClass *object = new(custom_alloc) MyClass(arguments here);
// do the work with object
delete(custom_alloc) object;
elm::io::p
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
elm::t::size
uint64 size
Definition: arch.h:35