101 using List = promeki::List<Buffer>;
116 _alloc(ms.alloc(
sz,
an))
130 _data(p), _owned(
own)
145 if(
o._data !=
nullptr) {
146 _alloc =
o._alloc.
ms.
alloc(
o._alloc.size,
o._alloc.align);
147 if(_alloc.
ptr ==
nullptr) { _size = 0;
return; }
148 o._alloc.ms.copy(
o._alloc, _alloc, _alloc.
size);
156 if(
this == &
o)
return *
this;
162 if(
o._data !=
nullptr) {
163 _alloc =
o._alloc.
ms.
alloc(
o._alloc.size,
o._alloc.align);
164 if(_alloc.
ptr !=
nullptr) {
176 _alloc(
o._alloc), _data(
o._data), _owned(
o._owned), _size(
o._size)
186 if(
this == &
o)
return *
this;
208 bool isValid()
const {
return _data !=
nullptr; }
214 void *
data()
const {
return _data; }
237 size_t size()
const {
return _size; }
262 if(_data ==
nullptr)
return 0;
263 return _alloc.
size -
static_cast<size_t>(
264 static_cast<uint8_t *
>(_data) -
306 _data =
static_cast<uint8_t *
>(_alloc.
ptr) + bytes;
352 void *_data =
nullptr;
354 mutable size_t _size = 0;
Generic memory buffer descriptor with alignment and memory space support.
Definition buffer.h:85
Error fill(char value) const
Fills the entire buffer with the given byte value.
Definition buffer.h:331
Buffer(void *p, size_t sz, size_t an=0, bool own=false, const MemSpace &ms=MemSpace::Default)
Wraps an existing memory pointer as a buffer.
Definition buffer.h:129
size_t size() const
Returns the logical content size in bytes.
Definition buffer.h:237
Buffer(Buffer &&o) noexcept
Move constructor. Transfers ownership from the source buffer.
Definition buffer.h:175
void shiftData(size_t bytes)
Shifts the data pointer forward from the allocation base.
Definition buffer.h:304
void setOwnershipEnabled(bool val)
Enables or disables ownership of the underlying memory.
Definition buffer.h:321
static size_t getPageSize()
Returns the system memory page size in bytes.
Buffer & operator=(Buffer &&o) noexcept
Move assignment operator. Transfers ownership from the source buffer.
Definition buffer.h:185
bool isValid() const
Returns true if the buffer has been allocated or assigned memory.
Definition buffer.h:208
void * odata() const
Returns the original allocation pointer.
Definition buffer.h:225
Buffer(const Buffer &o)
Copy constructor.
Definition buffer.h:144
~Buffer()
Destructor. Releases owned memory.
Definition buffer.h:200
void * data() const
Returns a pointer to the buffer data.
Definition buffer.h:214
size_t align() const
Returns the alignment of the buffer in bytes.
Definition buffer.h:282
static const size_t DefaultAlign
Default memory alignment in bytes.
Definition buffer.h:98
size_t availSize() const
Returns the available space from data() to the end of the allocation.
Definition buffer.h:261
void setSize(size_t s) const
Sets the logical content size.
Definition buffer.h:247
Buffer(size_t sz, size_t an=DefaultAlign, const MemSpace &ms=MemSpace::Default)
Allocates a buffer of the given size.
Definition buffer.h:115
Buffer()=default
Constructs an invalid (empty) buffer.
promeki::List< Ptr > PtrList
List of shared Buffer pointers.
Definition buffer.h:104
bool isHostAccessible() const
Returns true if the buffer memory is directly accessible from the host CPU.
Definition buffer.h:315
size_t allocSize() const
Returns the total allocation size in bytes.
Definition buffer.h:276
const MemAllocation & allocation() const
Returns the underlying allocation descriptor.
Definition buffer.h:294
Error copyFrom(const void *src, size_t bytes, size_t offset=0) const
Copies data from an external source into the buffer.
promeki::List< Buffer > List
List of Buffer values.
Definition buffer.h:101
const MemSpace & memSpace() const
Returns the memory space this buffer was allocated from.
Definition buffer.h:288
Buffer & operator=(const Buffer &o)
Copy assignment operator. Performs a deep copy.
Definition buffer.h:155
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
List()=default
Default constructor. Creates an empty list.
Abstraction for memory allocation in different address spaces.
Definition memspace.h:30
@ Default
Alias for System memory.
Definition memspace.h:36
bool copy(const MemAllocation &src, const MemAllocation &dst, size_t bytes) const
Copies bytes from a source allocation to a destination allocation.
Definition memspace.h:138
MemAllocation alloc(size_t bytes, size_t align) const
Allocates memory in this memory space.
Definition memspace.h:143
Error fill(void *ptr, size_t bytes, char value) const
Fills memory with a byte value.
Definition memspace.h:110
bool isHostAccessible(const MemAllocation &alloc) const
Returns true if the given allocation is directly accessible from the host CPU.
Definition memspace.h:73
void release(MemAllocation &alloc) const
Releases a previously allocated memory region.
Definition memspace.h:152
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88
Describes a memory allocation from a MemSpace.
Definition memspace.h:127
size_t size
Size of the allocation in bytes.
Definition memspace.h:129
size_t align
Alignment of the allocation in bytes.
Definition memspace.h:130
MemSpace ms
The memory space this was allocated from.
Definition memspace.h:131
void * ptr
Pointer to the allocated memory.
Definition memspace.h:128