Allocator.h File Reference
Memory allocators supporting uninitialized allocation and object construction. More...
#include <stdint.h>
#include "object/RawStorage.h"
#include "object/PlacementNew.h"
#include "logging/singleton.h"
Go to the source code of this file.
Data Structures | |
class | object::RawStorageAllocator< tag, mem_size > |
Allocator allocating from RawStorage. More... | |
class | object::OneBlockAllocator< tag, mem_size > |
Pseudo-allocator supporting only one allocation. More... | |
struct | object::OneBlockAllocator< tag, mem_size >::Buffer |
class | object::NewAllocator |
Allocator using standard C++ new and delete operators. More... | |
Namespaces | |
namespace | object |
Defines | |
#define | DEFAULT_RAWSTORAGEALLOCATOR_MEM_SIZE 0xffff |
Memory size for RawStorageAllocator used as default Allocator on AVR platform. | |
Typedefs | |
typedef NewAllocator | object::Allocator |
Default allocator. | |
Functions | |
template<typename tag , uint64_t mem_size> | |
void * | operator new (std::size_t size, const object::RawStorageAllocator< tag, mem_size > &allocator) throw () |
Allocate a new object using RawStorageAllocator and call constructor. | |
void * | operator new (std::size_t size, const object::NewAllocator &allocator) throw () |
Allocate a new object using NewAllocator and call constructor. |
Detailed Description
Memory allocators supporting uninitialized allocation and object construction.
- Introduction:
This file defines two allocators:
- object::RawStorageAllocator which impelments allocation from a constant size memory pool. It's suitalble for the AVR platform, but may be used on other platforms as well.
- object::NewAllocator uses standard C++ new and delete operators for memory management. It's not available for AVR platform.
This file also defines a default allocator: object::Allocator.
- Examples using default allocator:
- allocate unintialized raw buffer (100 bytes)
uint8_t * p = object::Allocator::alloc(100); // ... object::Allocator::free(p);
- allocate unintialized
int
array withn
elementsuint8_t * p = object::Allocator::alloc_array<int>(n); // ... object::Allocator::free_array(p);
- create an object in memory allocated by object::Allocator
MyObject * p = new (object::Allocator()) MyObject(constructor_argument); // ... object::Allocator::destroy(p);
- allocate unintialized raw buffer (100 bytes)
Define Documentation
#define DEFAULT_RAWSTORAGEALLOCATOR_MEM_SIZE 0xffff |
Memory size for RawStorageAllocator used as default Allocator on AVR platform.
Define it before including Allocator.h to make another amout of memory available for allocations via Allocator.
Default value is 255 bytes on AVR platform, 65535 bytes otherwise.
Function Documentation
void* operator new | ( | std::size_t | size, | |
const object::NewAllocator & | allocator | |||
) | throw () |
Allocate a new object using NewAllocator and call constructor.
- Returns:
- Pointer to constructed object. NULL if out of memory.
- Examples:
- using default allocator (object::Allocator), one constructor parameter
MyObject * p = new (object::Allocator()) MyObject(constructor_argument); // ... object::Allocator::destroy(p);
- using own allocator, no constructor parameters
MyObject2 * p = new (MyAllocator()) MyObject2; // ... MyAllocator::destroy(p);
template<typename tag , uint64_t mem_size>
void* operator new | ( | std::size_t | size, | |
const object::RawStorageAllocator< tag, mem_size > & | allocator | |||
) | throw () [inline] |
Allocate a new object using RawStorageAllocator and call constructor.
- Returns:
- Pointer to constructed object. NULL if out of memory.
- Examples:
- using default allocator (object::Allocator), one constructor parameter
MyObject * p = new (object::Allocator()) MyObject(constructor_argument); // ... object::Allocator::destroy(p);
- using own allocator, no constructor parameters
MyObject2 * p = new (MyAllocator()) MyObject2; // ... MyAllocator::destroy(p);