Common (static) functionality for unaligned and aligned memory allocation.
More...
#include <memory_allocation.h>
|
template<typename Type > |
static Type * | New () |
| Allocates memory for an instance of type Type and default-initializes it. More...
|
|
template<typename Type , typename Arg1 , ... > |
static Type * | New (Arg1 argument1,...) |
| Allocates memory unaligned for an instance of type Type and initializes it with the specified arguments. More...
|
|
template<typename Type > |
static void | Delete (Type *to_delete) |
| Destructs an instance of type Type and frees the allocated memory. More...
|
|
static size_t | AllocatedBytes () |
| Returns the total number of bytes currently allocated. More...
|
|
static void * | Allocate (size_t size) |
| Allocates size bytes of memory (unaligned). More...
|
|
static void | Free (void *ptr) |
| Frees memory that has been allocated by Allocation::Allocate() for some pointer ptr . More...
|
|
static void * | AllocateAligned (size_t alignment, size_t size) |
| Allocates size bytes of memory with alignment alignment . More...
|
|
static void | FreeAligned (void *ptr) |
| Frees memory that has been allocated by Allocation::AllocateAligned() or Allocation::AllocateCacheAligned() for some pointer ptr . More...
|
|
static void * | AllocateCacheAligned (size_t size) |
| Allocates size bytes of cache-aligned memory. More...
|
|
Common (static) functionality for unaligned and aligned memory allocation.
This class is a wrapper for the functions in embb/base/c/memory_allocation.h
template<typename Type >
static Type* embb::base::Allocation::New |
( |
| ) |
|
|
static |
Allocates memory for an instance of type Type
and default-initializes it.
Keeps track of allocated memory in debug mode.
- Returns
- Pointer to new instance of type
Type
- Exceptions
-
- See also
- Delete()
- Dynamic memory allocation
size+3*sizeof(size_t)
bytes in debug mode, otherwise size
bytes
- Concurrency
- Thread-safe
- Template Parameters
-
Type | Type of the object to be allocated |
template<typename Type , typename Arg1 , ... >
static Type* embb::base::Allocation::New |
( |
Arg1 |
argument1, |
|
|
|
... |
|
) |
| |
|
static |
Allocates memory unaligned for an instance of type Type
and initializes it with the specified arguments.
Keeps track of allocated memory in debug mode.
- Returns
- Pointer to new instance of type
Type
- Exceptions
-
- See also
- Delete()
- Dynamic memory allocation
size+3*sizeof(size_t)
bytes in debug mode, otherwise size
bytes
- Concurrency
- Thread-safe
- Template Parameters
-
Type | Type of the instance to be allocated |
Arg1 | Type of (first) constructor argument |
- Parameters
-
[in] | argument1 | (First) argument for constructor of Type |
template<typename Type >
static void embb::base::Allocation::Delete |
( |
Type * |
to_delete | ) |
|
|
static |
Destructs an instance of type Type
and frees the allocated memory.
- Template Parameters
-
Type | Type of instance to be deleted |
- Parameters
-
[in,out] | to_delete | Instance to be deleted |
static size_t embb::base::Allocation::AllocatedBytes |
( |
| ) |
|
|
static |
Returns the total number of bytes currently allocated.
Wrapper for C function embb_get_bytes_allocated().
- Returns
- Number of currently allocated bytes in debug mode, otherwise 0.
- Concurrency
- Thread-safe and wait-free
static void* embb::base::Allocation::Allocate |
( |
size_t |
size | ) |
|
|
static |
Allocates size
bytes of memory (unaligned).
Wrapper for C function embb_allocate().
Keeps track of allocated memory in debug mode.
- Returns
- NULL in case of failure, otherwise address of allocated memory block.
- Exceptions
-
- Dynamic memory allocation
size+3*sizeof(size_t)
bytes in debug mode, otherwise size
bytes
- Concurrency
- Thread-safe
- Note
- Memory allocated using this function must be freed using Allocation::Free().
- See also
- AllocateAligned(), AllocateCacheAligned(), Free()
- Parameters
-
[in] | size | Size of memory block to be allocated in bytes |
static void embb::base::Allocation::Free |
( |
void * |
ptr | ) |
|
|
static |
Frees memory that has been allocated by Allocation::Allocate() for some pointer ptr
.
Wrapper for C function embb_free().
Keeps track of freed memory in debug mode.
- Concurrency
- Thread-safe
- See also
- Allocate()
- Parameters
-
[in,out] | ptr | Pointer to memory block to be freed |
static void* embb::base::Allocation::AllocateAligned |
( |
size_t |
alignment, |
|
|
size_t |
size |
|
) |
| |
|
static |
Allocates size
bytes of memory with alignment alignment
.
Wrapper for C function embb_alloc_aligned().
This function can be used to align objects to certain boundaries such as cache lines, memory pages, etc.
Keeps track of allocated memory in debug mode.
It is not required that size
is a multiple of alignment
as, e.g., for the aligned_alloc
function of the C11 Standard.
- Precondition
- The alignment has to be power of 2 and a multiple of
size(void*)
.
- Postcondition
- The returned pointer is a multiple of
alignment
.
- Returns
- NULL in case of failure, otherwise address of allocated memory block.
- Exceptions
-
- Dynamic memory allocation
- Debug mode: Let
n
be the number of aligned cells necessary to fit the payload. Then, (n+1)*alignment+3*size_of(size_t)-1
bytes are allocated.
Release mode: size
bytes are requested using the functions provided by the operating systems.
- Concurrency
- Thread-safe
- Note
- Memory allocated using this function must be freed using Allocation::FreeAligned().
- See also
- Allocate(), AllocateCacheAligned(), FreeAligned()
- Parameters
-
[in] | alignment | Alignment in bytes |
[in] | size | Size of memory block to be allocated in bytes |
static void embb::base::Allocation::FreeAligned |
( |
void * |
ptr | ) |
|
|
static |
static void* embb::base::Allocation::AllocateCacheAligned |
( |
size_t |
size | ) |
|
|
static |