Skip to content

MemoryFile

class MemoryFile : public File

A File implementation that reads from and writes to a memory buffer.

Functions

Name Description
MemoryFile Creates a new MemoryFile instance.
MemoryFile Creates a new MemoryFile instance from a memory buffer.
~MemoryFile Destroys the instance and release the memory buffer if owned.
GetPath @inherit
Eof @inherit
Read @inherit
Write @inherit
Length @inherit
Seek @inherit
Position @inherit
GetPtr @inherit
IsValid @inherit
Open Opens a new memory buffer with the specified size.
OpenMem Opens a memory buffer.
OpenToMem Opens a memory buffer from a file content.
OpenFileToMem Copies data from a file instance to a memory buffer. The file content is entirely copied.
Close Closes the memory buffer and releases associated resources.

Function Details

Close

void Close()

Closes the memory buffer and releases associated resources.

Eof

bool Eof() override

@inherit

GetPath

[[nodiscard]] AmOsString GetPath() const override

@inherit

GetPtr

AmVoidPtr GetPtr() override

@inherit

IsValid

[[nodiscard]] bool IsValid() const override

@inherit

Length

AmSize Length() override

@inherit

MemoryFile

MemoryFile()

Creates a new MemoryFile instance.

MemoryFile(AmUInt8Buffer buffer, AmSize size, bool copy = false, bool takeOwnership = true)

Creates a new MemoryFile instance from a memory buffer.

Parameter buffer
The memory buffer to manage in this instance.
Parameter size
The size of the memory buffer.
Parameter copy
If true, the memory buffer will be copied.
Parameter takeOwnership
If true, the memory buffer will be owned by this instance, and released when this instance is destroyed.

Open

AmResult Open(AmSize size)

Opens a new memory buffer with the specified size.

Parameter size
The size of the buffer.
Return
The result of the operation.

OpenFileToMem

AmResult OpenFileToMem(File* file)

Copies data from a file instance to a memory buffer. The file content is entirely copied.

Parameter file
The file instance to copy data from.
Return
The result of the operation.

OpenMem

AmResult OpenMem(AmConstUInt8Buffer buffer, AmSize size, bool copy = false, bool takeOwnership = true)

Opens a memory buffer.

Parameter buffer
The memory buffer to open.
Parameter size
The size of the memory buffer.
Parameter copy
If true, the memory buffer will be copied.
Parameter takeOwnership
If true, the memory buffer will be owned by this instance, and released when this instance is destroyed.
Return
The result of the operation.

OpenToMem

AmResult OpenToMem(const std::filesystem::path& fileName)

Opens a memory buffer from a file content.

Parameter fileName
The path to the file to open.
Return
The result of the operation.

Position

AmSize Position() override

@inherit

Read

AmSize Read(AmUInt8Buffer dst, AmSize bytes) override

@inherit

Seek

void Seek(AmInt64 offset, eFileSeekOrigin origin) override

@inherit

Write

AmSize Write(AmConstUInt8Buffer src, AmSize bytes) override

@inherit

~MemoryFile

~MemoryFile() override

Destroys the instance and release the memory buffer if owned.