Compute Library
 22.05
AllocatorWrapper Class Referencefinal

Default malloc allocator implementation. More...

#include <AllocatorWrapper.h>

Public Member Functions

 AllocatorWrapper (const AclAllocator &backing_allocator) noexcept
 Default Constructor. More...
 
 AllocatorWrapper (const AllocatorWrapper &) noexcept=default
 
 AllocatorWrapper (AllocatorWrapper &&) noexcept=default
 
AllocatorWrapperoperator= (const AllocatorWrapper &) noexcept=delete
 
AllocatorWrapperoperator= (AllocatorWrapper &&other) noexcept=default
 
void * alloc (size_t size)
 Allocate a chunk of memory of a given size in bytes. More...
 
void free (void *ptr)
 Free an allocated memory block. More...
 
void * aligned_alloc (size_t size, size_t alignment)
 Allocate a chunk of memory of a given size in bytes, while honoring a given alignment requirement. More...
 
void aligned_free (void *ptr)
 Free an aligned memory block. More...
 
void set_user_data (void *user_data)
 Set user data to be used by the allocator. More...
 

Detailed Description

Default malloc allocator implementation.

Definition at line 32 of file AllocatorWrapper.h.

Constructor & Destructor Documentation

◆ AllocatorWrapper() [1/3]

AllocatorWrapper ( const AclAllocator backing_allocator)
noexcept

Default Constructor.

Parameters
[in]backing_allocatorBacking memory allocator to be used

Definition at line 29 of file AllocatorWrapper.cpp.

30  : _backing_allocator(backing_allocator)
31 {
32 }

◆ AllocatorWrapper() [2/3]

AllocatorWrapper ( const AllocatorWrapper )
defaultnoexcept

◆ AllocatorWrapper() [3/3]

AllocatorWrapper ( AllocatorWrapper &&  )
defaultnoexcept

Member Function Documentation

◆ aligned_alloc()

void * aligned_alloc ( size_t  size,
size_t  alignment 
)

Allocate a chunk of memory of a given size in bytes, while honoring a given alignment requirement.

Parameters
[in]sizeSize of memory to allocate in bytes
[in]alignmentAlignment requirements
Returns
A pointer to the allocated memory if successful else nullptr

Definition at line 46 of file AllocatorWrapper.cpp.

References AclAllocator::aligned_alloc, ARM_COMPUTE_ERROR_ON, and AclAllocator::user_data.

47 {
48  ARM_COMPUTE_ERROR_ON(_backing_allocator.aligned_alloc == nullptr);
49  return _backing_allocator.aligned_alloc(_backing_allocator.user_data, size, alignment);
50 }
void * user_data
Definition: AclTypes.h:130
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void *(* aligned_alloc)(void *user_data, size_t size, size_t alignment)
Allocate a block of size bytes of memory.
Definition: AclTypes.h:121

◆ aligned_free()

void aligned_free ( void *  ptr)

Free an aligned memory block.

Parameters
[in]ptrPointer to the memory to release

Definition at line 52 of file AllocatorWrapper.cpp.

References AclAllocator::aligned_free, ARM_COMPUTE_ERROR_ON, and AclAllocator::user_data.

53 {
54  ARM_COMPUTE_ERROR_ON(_backing_allocator.aligned_free == nullptr);
55  _backing_allocator.aligned_free(_backing_allocator.user_data, ptr);
56 }
void * user_data
Definition: AclTypes.h:130
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void(* aligned_free)(void *user_data, void *ptr)
Allocate a block of size bytes of memory.
Definition: AclTypes.h:127

◆ alloc()

void * alloc ( size_t  size)

Allocate a chunk of memory of a given size in bytes.

Parameters
[in]sizeSize of memory to allocate in bytes
Returns
A pointer to the allocated memory if successful else nullptr

Definition at line 34 of file AllocatorWrapper.cpp.

References AclAllocator::alloc, ARM_COMPUTE_ERROR_ON, and AclAllocator::user_data.

35 {
36  ARM_COMPUTE_ERROR_ON(_backing_allocator.alloc == nullptr);
37  return _backing_allocator.alloc(_backing_allocator.user_data, size);
38 }
void * user_data
Definition: AclTypes.h:130
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void *(* alloc)(void *user_data, size_t size)
Allocate a block of size bytes of memory.
Definition: AclTypes.h:107

◆ free()

void free ( void *  ptr)

Free an allocated memory block.

Parameters
[in]ptrPointer to allocated memory

Definition at line 40 of file AllocatorWrapper.cpp.

References ARM_COMPUTE_ERROR_ON, AclAllocator::free, and AclAllocator::user_data.

41 {
42  ARM_COMPUTE_ERROR_ON(_backing_allocator.free == nullptr);
43  _backing_allocator.free(_backing_allocator.user_data, ptr);
44 }
void * user_data
Definition: AclTypes.h:130
void(* free)(void *user_data, void *ptr)
Release a block of size bytes of memory.
Definition: AclTypes.h:113
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ operator=() [1/2]

AllocatorWrapper& operator= ( const AllocatorWrapper )
deletenoexcept

◆ operator=() [2/2]

AllocatorWrapper& operator= ( AllocatorWrapper &&  other)
defaultnoexcept

◆ set_user_data()

void set_user_data ( void *  user_data)

Set user data to be used by the allocator.

Parameters
[in]user_dataUser data to be used by the allocator

Definition at line 58 of file AllocatorWrapper.cpp.

References AclAllocator::user_data.

59 {
60  if(user_data != nullptr)
61  {
62  _backing_allocator.user_data = user_data;
63  }
64 }
void * user_data
Definition: AclTypes.h:130

The documentation for this class was generated from the following files: