Compute Library
 23.11
MemoryRegion Class Referencefinal

Memory region CPU implementation. More...

#include <MemoryRegion.h>

Collaboration diagram for MemoryRegion:
[legend]

Public Member Functions

 MemoryRegion (size_t size, size_t alignment=0)
 Constructor. More...
 
 MemoryRegion (void *ptr, size_t size)
 
 MemoryRegion (const MemoryRegion &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 MemoryRegion (MemoryRegion &&)=default
 Default move constructor. More...
 
MemoryRegionoperator= (const MemoryRegion &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
MemoryRegionoperator= (MemoryRegion &&)=default
 Default move assignment operator. More...
 
void * buffer () final
 Returns the pointer to the allocated data. More...
 
const void * buffer () const final
 Returns the pointer to the allocated data. More...
 
std::unique_ptr< IMemoryRegionextract_subregion (size_t offset, size_t size) final
 Extract a sub-region from the memory. More...
 
- Public Member Functions inherited from IMemoryRegion
 IMemoryRegion (size_t size)
 Default constructor. More...
 
virtual ~IMemoryRegion ()=default
 Virtual Destructor. More...
 
size_t size () const
 Memory region size accessor. More...
 
void set_size (size_t size)
 Sets size of region. More...
 

Detailed Description

Memory region CPU implementation.

Definition at line 35 of file MemoryRegion.h.

Constructor & Destructor Documentation

◆ MemoryRegion() [1/4]

MemoryRegion ( size_t  size,
size_t  alignment = 0 
)
inline

Constructor.

Parameters
[in]sizeRegion size
[in]alignmentAlignment in bytes of the base pointer. Defaults to 0

Definition at line 43 of file MemoryRegion.h.

43  : IMemoryRegion(size), _mem(nullptr), _ptr(nullptr)
44  {
45  if (size != 0)
46  {
47  // Allocate backing memory
48  size_t space = size + alignment;
49  _mem = std::shared_ptr<uint8_t>(new uint8_t[space](), [](uint8_t *ptr) { delete[] ptr; });
50  _ptr = _mem.get();
51 
52  // Calculate alignment offset
53  if (alignment != 0)
54  {
55  void *aligned_ptr = _mem.get();
56  std::align(alignment, size, aligned_ptr, space);
57  _ptr = aligned_ptr;
58  }
59  }
60  }

References IMemoryRegion::size().

◆ MemoryRegion() [2/4]

MemoryRegion ( void *  ptr,
size_t  size 
)
inline

Definition at line 61 of file MemoryRegion.h.

61  : IMemoryRegion(size), _mem(nullptr), _ptr(nullptr)
62  {
63  if (size != 0)
64  {
65  _ptr = ptr;
66  }
67  }

References IMemoryRegion::size().

◆ MemoryRegion() [3/4]

MemoryRegion ( const MemoryRegion )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ MemoryRegion() [4/4]

MemoryRegion ( MemoryRegion &&  )
default

Default move constructor.

Member Function Documentation

◆ buffer() [1/2]

const void* buffer ( ) const
inlinefinalvirtual

Returns the pointer to the allocated data.

Returns
Pointer to the allocated data

Implements IMemoryRegion.

Definition at line 82 of file MemoryRegion.h.

83  {
84  return _ptr;
85  }

◆ buffer() [2/2]

void* buffer ( )
inlinefinalvirtual

Returns the pointer to the allocated data.

Returns
Pointer to the allocated data

Implements IMemoryRegion.

Definition at line 78 of file MemoryRegion.h.

79  {
80  return _ptr;
81  }

◆ extract_subregion()

std::unique_ptr<IMemoryRegion> extract_subregion ( size_t  offset,
size_t  size 
)
inlinefinalvirtual

Extract a sub-region from the memory.

Warning
Ownership is maintained by the parent memory, while a wrapped raw memory region is returned by this function. Thus parent memory should not be released before this.
Parameters
[in]offsetOffset to the region
[in]sizeSize of the region
Returns
A wrapped memory sub-region with no ownership of the underlying memory

Implements IMemoryRegion.

Definition at line 86 of file MemoryRegion.h.

87  {
88  if (_ptr != nullptr && (offset < _size) && (_size - offset >= size))
89  {
90  return std::make_unique<MemoryRegion>(static_cast<uint8_t *>(_ptr) + offset, size);
91  }
92  else
93  {
94  return nullptr;
95  }
96  }

References offset(), and IMemoryRegion::size().

◆ operator=() [1/2]

MemoryRegion& operator= ( const MemoryRegion )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

MemoryRegion& operator= ( MemoryRegion &&  )
default

Default move assignment operator.


The documentation for this class was generated from the following file:
arm_compute::IMemoryRegion::size
size_t size() const
Memory region size accessor.
Definition: IMemoryRegion.h:72
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
arm_compute::IMemoryRegion::IMemoryRegion
IMemoryRegion(size_t size)
Default constructor.
Definition: IMemoryRegion.h:40