ReXGlue SDK
Loading...
Searching...
No Matches
rex::memory::MappedMemory Class Reference

#include <rex/memory/virtual_memory.h>

Inheritance diagram for rex::memory::MappedMemory:
[legend]

Public Types

enum class  Mode : u8 { kRead , kReadWrite }

Public Member Functions

 MappedMemory (void *data, size_t size)
std::unique_ptr< MappedMemory > Range (size_t offset, size_t length) const
u8 * GetData () const
size_t GetSize () const
virtual void Close (u64 truncate_size=0)
virtual void Flush ()
virtual bool Remap (size_t offset, size_t length)

Static Public Member Functions

static std::unique_ptr< MappedMemory > Open (const std::filesystem::path &path, Mode mode, size_t offset=0, size_t length=0)

Protected Attributes

void * data_ = nullptr
size_t size_ = 0

Additional Inherited Members

Protected Member Functions inherited from rex::NonCopyable
 NonCopyable (const NonCopyable &)=delete
NonCopyable & operator= (const NonCopyable &)=delete

Detailed Description

A file, or a range of a file, mapped into host memory.

Constructor & Destructor Documentation

◆ MappedMemory()

rex::memory::MappedMemory::MappedMemory ( void * data,
size_t size )
inline

Wraps memory the object does not own.

Member Function Documentation

◆ Close()

virtual void rex::memory::MappedMemory::Close ( u64 truncate_size = 0)
inlinevirtual

Unmaps the memory and closes the file.

Parameters
truncate_sizeSize to truncate the file to, or 0 to keep its size.

◆ GetData()

u8 * rex::memory::MappedMemory::GetData ( ) const
inline

Returns the start of the mapped memory. It is null once closed.

◆ Open()

std::unique_ptr< MappedMemory > rex::memory::MappedMemory::Open ( const std::filesystem::path & path,
Mode mode,
size_t offset = 0,
size_t length = 0 )
static

Maps an existing file.

Parameters
offsetByte offset of the mapped range in the file.
lengthByte count of the range, or 0 to map to the end of the file.
Returns
The mapping, or null on failure.

◆ Range()

std::unique_ptr< MappedMemory > rex::memory::MappedMemory::Range ( size_t offset,
size_t length ) const
inline

Returns a view of part of this mapping, valid while it stays open.

Parameters
offsetByte offset of the view in this mapping.

◆ Remap()

virtual bool rex::memory::MappedMemory::Remap ( size_t offset,
size_t length )
inlinevirtual

Maps a different range of the file.

Parameters
offsetByte offset of the new range in the file.
lengthByte count of the new range, or 0 to map to the end of the file.
Returns
True on success. Always false on POSIX.

The documentation for this class was generated from the following file: