openMSX
|
This class manages the lifetime of a block of memory. More...
#include <MemBuffer.hh>
Public Member Functions | |
MemBuffer () | |
Construct an empty MemBuffer, no memory is allocated. | |
MemBuffer (size_t size) | |
Construct a (uninitialized) memory buffer of given size. | |
MemBuffer (MemBuffer &&other) noexcept | |
Move constructor. | |
MemBuffer & | operator= (MemBuffer &&other) noexcept |
Move assignment. | |
~MemBuffer () | |
Free the memory buffer. | |
const T * | data () const |
Returns pointer to the start of the memory buffer. | |
T * | data () |
T * | begin () |
const T * | begin () const |
T * | end () |
const T * | end () const |
const T & | operator[] (size_t i) const |
Access elements in the memory buffer. | |
T & | operator[] (size_t i) |
bool | empty () const |
size_t | size () const |
T & | front () |
const T & | front () const |
T & | back () |
const T & | back () const |
operator std::span< T > () | |
operator std::span< const T > () const | |
std::span< const T > | first (size_t n) const |
std::span< T > | first (size_t n) |
std::span< const T > | subspan (size_t offset, size_t n=std::dynamic_extent) const |
std::span< T > | subspan (size_t offset, size_t n=std::dynamic_extent) |
void | resize (size_t size) |
Grow or shrink the memory block. | |
void | clear () |
Free the allocated memory block and set the current size to 0. | |
This class manages the lifetime of a block of memory.
Its two main use cases are: 1) As a safer alternative for new[] / delete[]. Using this class makes sure the memory block is always properly cleaned up. Also in case of exceptions. 2) As an alternative for vector<byte> ('byte' or other primitive types). The main difference with vector is that the allocated block is left uninitialized. This can be a bit more efficient if the block will anyway soon be overwritten.
Like vector this buffer can dynamically grow or shrink. But it's not optimized for this case (it doesn't keep track of extra capacity). If you need frequent resizing prefer to use vector instead of this class.
Definition at line 31 of file MemBuffer.hh.
|
inline |
Construct an empty MemBuffer, no memory is allocated.
Definition at line 38 of file MemBuffer.hh.
|
inlineexplicit |
Construct a (uninitialized) memory buffer of given size.
Definition at line 46 of file MemBuffer.hh.
|
inlinenoexcept |
Move constructor.
Definition at line 53 of file MemBuffer.hh.
|
inline |
Free the memory buffer.
Definition at line 71 of file MemBuffer.hh.
|
inline |
Definition at line 113 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::empty().
|
inline |
Definition at line 118 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::empty().
|
inline |
Definition at line 82 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::data().
Referenced by openmsx::Ram::begin(), and openmsx::Ram::begin().
|
inline |
Definition at line 83 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::data().
|
inline |
Free the allocated memory block and set the current size to 0.
Definition at line 168 of file MemBuffer.hh.
Referenced by openmsx::FileBase::munmap(), and openmsx::MemBuffer< T, ALIGNMENT >::resize().
|
inline |
Definition at line 80 of file MemBuffer.hh.
|
inline |
Returns pointer to the start of the memory buffer.
This method can be called even when there's no buffer allocated.
Definition at line 79 of file MemBuffer.hh.
Referenced by openmsx::OutputBuffer::allocate(), openmsx::DeltaBlockCopy::apply(), openmsx::MemBuffer< T, ALIGNMENT >::begin(), openmsx::MemBuffer< T, ALIGNMENT >::begin(), openmsx::Ram::clear(), openmsx::DeltaBlockCopy::compress(), openmsx::ZMBVEncoder::compressFrame(), openmsx::Ram::data(), openmsx::Ram::data(), openmsx::DeltaBlockDiff::DeltaBlockDiff(), openmsx::MemBuffer< T, ALIGNMENT >::end(), openmsx::MemBuffer< T, ALIGNMENT >::end(), openmsx::RomDatabase::getBufferStart(), openmsx::DeltaBlockCopy::getData(), openmsx::OutputBuffer::getPosition(), openmsx::ZlibInflate::inflate(), openmsx::OutputBuffer::insertAt(), openmsx::XMLDocument::load(), openmsx::SettingsConfig::loadSetting(), openmsx::MemBuffer< byte >::operator std::span< byte >(), openmsx::MemBuffer< byte >::operator std::span< const byte >(), openmsx::ImGuiBitmapViewer::paint(), openmsx::RomDatabase::RomDatabase(), openmsx::VisibleSurface::saveScreenshotGL(), SDLSurfacePtr::SDLSurfacePtr(), and openmsx::OutputArchiveBase< Derived >::serialize_blob().
|
inline |
Definition at line 100 of file MemBuffer.hh.
Referenced by openmsx::MemBuffer< T, ALIGNMENT >::back(), openmsx::MemBuffer< T, ALIGNMENT >::back(), openmsx::MemBuffer< T, ALIGNMENT >::front(), openmsx::MemBuffer< T, ALIGNMENT >::front(), and openmsx::FileBase::mmap().
|
inline |
Definition at line 84 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::data(), and openmsx::MemBuffer< T, ALIGNMENT >::size().
Referenced by openmsx::OutputBuffer::allocate(), openmsx::Ram::end(), openmsx::Ram::end(), openmsx::OutputBuffer::insert_tuple_ptr(), openmsx::OutputBuffer::insertAt(), and openmsx::OutputBuffer::insertN().
|
inline |
Definition at line 85 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::data(), and openmsx::MemBuffer< T, ALIGNMENT >::size().
|
inline |
Definition at line 132 of file MemBuffer.hh.
|
inline |
Definition at line 127 of file MemBuffer.hh.
Referenced by openmsx::XMLDocument::load(), openmsx::SettingsConfig::loadSetting(), and openmsx::OutputArchiveBase< Derived >::serialize_blob().
|
inline |
Definition at line 103 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::empty().
|
inline |
Definition at line 108 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::empty().
|
inline |
Definition at line 125 of file MemBuffer.hh.
|
inline |
Definition at line 124 of file MemBuffer.hh.
|
inlinenoexcept |
Move assignment.
Definition at line 62 of file MemBuffer.hh.
|
inline |
Definition at line 94 of file MemBuffer.hh.
|
inline |
Access elements in the memory buffer.
Definition at line 89 of file MemBuffer.hh.
|
inline |
Grow or shrink the memory block.
In case of growing, the extra space is left uninitialized. It is possible (even likely) that the memory buffer is copied to a new location after this call, so data() will return a different pointer value.
Definition at line 156 of file MemBuffer.hh.
References openmsx::MemBuffer< T, ALIGNMENT >::clear(), and openmsx::MemBuffer< T, ALIGNMENT >::size().
Referenced by openmsx::DeltaBlockCopy::compress(), Base64::decode(), HexDump::decode(), openmsx::ZlibInflate::inflate(), openmsx::XMLDocument::load(), openmsx::SettingsConfig::loadSetting(), openmsx::RawFrame::RawFrame(), openmsx::RomDatabase::RomDatabase(), SDLSurfacePtr::SDLSurfacePtr(), and openmsx::WavData::WavData().
|
inline |
Definition at line 101 of file MemBuffer.hh.
Referenced by HexDump::decode(), Base64::decode_inplace(), HexDump::decode_inplace(), openmsx::MemBuffer< T, ALIGNMENT >::end(), openmsx::MemBuffer< T, ALIGNMENT >::end(), openmsx::WavData::getSample(), openmsx::WavData::getSize(), openmsx::CompressedFileAdapter::getSize(), openmsx::MemBuffer< byte >::operator std::span< byte >(), openmsx::MemBuffer< byte >::operator std::span< const byte >(), openmsx::CompressedFileAdapter::read(), openmsx::MemBuffer< T, ALIGNMENT >::resize(), and openmsx::Ram::size().
|
inline |
Definition at line 143 of file MemBuffer.hh.
|
inline |
Definition at line 137 of file MemBuffer.hh.
Referenced by openmsx::Rom::addPadding(), openmsx::RawFrame::getLineDirect(), and openmsx::CompressedFileAdapter::read().