ADTF  3.18.2
memorybuffer.h
Go to the documentation of this file.
1 
15 #ifndef _A_UTILS_UTIL_MEMORY_MEMORYBUFFER_INCLUDED_
16 #define _A_UTILS_UTIL_MEMORY_MEMORYBUFFER_INCLUDED_
17 
18 #include <memory>
19 
20 namespace a_util {
21 namespace memory {
23 class MemoryBuffer {
24 public:
27 
32  MemoryBuffer(std::size_t initial_size);
33 
39  MemoryBuffer(void* buffer, std::size_t size);
40 
43 
48  MemoryBuffer(const MemoryBuffer& other);
49 
56 
62  bool allocate(std::size_t new_size);
63 
67  void reset();
68 
73  std::size_t getSize() const;
74 
79  void* getPtr() const;
80 
86  void attach(void* buffer, std::size_t size);
87 
92  void swap(MemoryBuffer& other);
93 
94 private:
95  struct Implementation;
96  std::unique_ptr<Implementation> _impl;
97 };
98 
105 bool operator==(const MemoryBuffer& lhs, const MemoryBuffer& rhs);
106 
113 bool operator!=(const MemoryBuffer& lhs, const MemoryBuffer& rhs);
114 
115 } // namespace memory
116 } // namespace a_util
117 
118 #endif // _A_UTILS_UTIL_MEMORY_MEMORYBUFFER_INCLUDED_
Memory buffer class to encapsulate and manage raw contiguously memory.
Definition: memorybuffer.h:23
MemoryBuffer()
Default CTOR, not allocating any memory.
MemoryBuffer(void *buffer, std::size_t size)
CTOR attaching to memory from a an already existing buffer (non-owning!)
MemoryBuffer(std::size_t initial_size)
CTOR with initial size of the buffer (first allocates, then zero-initializes the buffer)
std::size_t getSize() const
Get the size of the currently managed memory.
void * getPtr() const
Get raw pointer to the current buffer.
void attach(void *buffer, std::size_t size)
Attach a pre-allocated buffer to the instance (non-owning!)
bool allocate(std::size_t new_size)
Allocate and zero-initialize a new memory buffer, freeing or detaching any managed memory.
MemoryBuffer & operator=(const MemoryBuffer &other)
Assignment operator, always allocating new memory and performing a deep copy.
void swap(MemoryBuffer &other)
Swap content of this object with other.
~MemoryBuffer()
DTOR, either detaching any referenced buffer or deleting allocated memory.
void reset()
Reset the memory (freeing or detaching any managed memory)
MemoryBuffer(const MemoryBuffer &other)
Copy constructor, always allocating new memory and performing a deep copy.
bool operator==(const MemoryBuffer &lhs, const MemoryBuffer &rhs)
Compare content of the managed memory of two memory buffer objects for equality.
bool operator!=(const StackPtr< T, StackSize, Alignment > &lhs, const StackPtr< T, StackSize, Alignment > &rhs)
Compare for inequality.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24