Embedded Multicore Building Blocks V1.0.0
Static Public Member Functions | List of all members
embb::base::Allocatable Class Reference

Overloaded new/delete operators. More...

#include <memory_allocation.h>

Static Public Member Functions

static void * operator new (size_t size)
 New operator. More...
 
static void operator delete (void *ptr, size_t size)
 Delete operator. More...
 
static void * operator new[] (size_t size)
 Array new operator. More...
 
static void operator delete[] (void *ptr, size_t size)
 Array delete operator. More...
 

Detailed Description

Overloaded new/delete operators.

Classes that derive from this class will use the EMBB methods for dynamic allocation and deallocation of memory (Allocation::Allocate() and Allocation::Free()). In debug mode, memory consumption is tracked in order to detect memory leaks.

See also
CacheAlignedAllocatable

Member Function Documentation

static void* embb::base::Allocatable::operator new ( size_t  size)
static

New operator.

Allocates size bytes of memory. Must not be called directly!

Returns
Pointer to allocated block of memory
Exceptions
embb::base::NoMemoryExceptionif not enough memory is available.
Concurrency
Thread-safe
Dynamic memory allocation
See Allocation::Allocate()
See also
operator delete()
Parameters
[in]sizeSize of the memory block in bytes
static void embb::base::Allocatable::operator delete ( void *  ptr,
size_t  size 
)
static

Delete operator.

Deletes size bytes of memory pointed to by ptr. Must not be called directly!

Concurrency
Thread-safe
See also
operator new()
Parameters
[in,out]ptrPointer to memory block to be freed
[in]sizeSize of the memory block in bytes
static void* embb::base::Allocatable::operator new[] ( size_t  size)
static

Array new operator.

Allocates an array of size bytes. Must not be called directly!

Remarks
Note that the global new[], calling this function, might return a different address. This is stated in the standard (5.3.4 New [expr.new]):
"A new-expression passes the amount of space requested to the allocation function as the first argument of type std::size_t. That argument shall be no less than the size of the object being created; it may be greater than the size of the object being created only if the object is an array."
So, even if the returned pointer of this function is aligned, the pointer to the array returned by global new[] need not be. For example, when using GCC 4.8.3 (64 bit), the size of the array is kept in the first 8 bytes of the allocated memory.
Returns
Pointer to allocated block of memory
Concurrency
Thread-safe
Dynamic memory allocation
See Allocation::Allocate()
Exceptions
embb::base::NoMemoryExceptionif not enough memory is available.
See also
operator delete[]()
Parameters
[in]sizeSize of the array in bytes
static void embb::base::Allocatable::operator delete[] ( void *  ptr,
size_t  size 
)
static

Array delete operator.

Deletes array of size bytes pointed to by ptr. Must not be called directly!

Concurrency
Thread-safe
See also
operator new[]()
Parameters
[in,out]ptrPointer to the array to be freed
[in]sizeSize of the array in bytes