Core/Stream: Add MemoryMapped stream options (allowing for direct memory access)

This commit is contained in:
SirLynix
2023-03-03 13:18:51 +01:00
parent 3000345eab
commit 34abeeb7bd
9 changed files with 103 additions and 72 deletions

View File

@@ -42,13 +42,26 @@ namespace Nz
*/
MemoryView::MemoryView(const void* ptr, UInt64 size) :
Stream(StreamOption::None, OpenMode::ReadOnly),
Stream(StreamOption::MemoryMapped, OpenMode::ReadOnly),
m_ptr(static_cast<UInt8*>(const_cast<void*>(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only
m_pos(0),
m_size(size)
{
}
/*!
* \brief Flushes the stream
*/
void MemoryView::FlushStream()
{
// Nothing to do
}
void* MemoryView::GetMemoryMappedPointer() const
{
return m_ptr;
}
/*!
* \brief Gets the size of the raw memory
* \return Size of the memory
@@ -59,15 +72,6 @@ namespace Nz
return m_size;
}
/*!
* \brief Flushes the stream
*/
void MemoryView::FlushStream()
{
// Nothing to do
}
/*!
* \brief Reads blocks
* \return Number of blocks read
@@ -100,15 +104,6 @@ namespace Nz
return true;
}
/*!
* \brief Gets the position of the cursor
* \return Position of the cursor
*/
UInt64 MemoryView::TellStreamCursor() const
{
return m_pos;
}
/*!
* \brief Checks whether the stream reached the end of the stream
* \return true if cursor is at the end of the stream
@@ -118,6 +113,15 @@ namespace Nz
return m_pos >= m_size;
}
/*!
* \brief Gets the position of the cursor
* \return Position of the cursor
*/
UInt64 MemoryView::TellStreamCursor() const
{
return m_pos;
}
/*!
* \brief Writes blocks
* \return Number of blocks written