Plasma Engine  2.0
Loading...
Searching...
No Matches
MemoryMappedFile.h
1#pragma once
2
3#include <Foundation/Types/UniquePtr.h>
4
6
8class PL_FOUNDATION_DLL plMemoryMappedFile
9{
10 PL_DISALLOW_COPY_AND_ASSIGN(plMemoryMappedFile);
11
12public:
15
16 enum class Mode
17 {
18 None,
19 ReadOnly,
20 ReadWrite,
21 };
22
24 enum class OffsetBase
25 {
26 Start,
27 End,
29 };
30
31#if PL_ENABLED(PL_SUPPORTS_MEMORY_MAPPED_FILE) || defined(PL_DOCS)
37 plResult Open(plStringView sAbsolutePath, Mode mode);
38#endif
39
40#if PL_ENABLED(PL_SUPPORTS_SHARED_MEMORY) || defined(PL_DOCS)
46 plResult OpenShared(plStringView sSharedName, plUInt64 uiSize, Mode mode);
47#endif
48
50 void Close();
51
53 Mode GetMode() const;
54
56 plUInt64 GetFileSize() const;
57
59 const void* GetReadPointer(plUInt64 uiOffset = 0, OffsetBase base = OffsetBase::Start) const;
60
62 void* GetWritePointer(plUInt64 uiOffset = 0, OffsetBase base = OffsetBase::Start);
63
64private:
66};
Allows to map an entire file into memory for random access.
Definition MemoryMappedFile.h:9
OffsetBase
The start point for interpreting byte offsets into the memory.
Definition MemoryMappedFile.h:25
Mode
Definition MemoryMappedFile.h:17
plResult Open(plStringView sAbsolutePath, Mode mode)
Attempts to open the given file and map it into memory.
plResult OpenShared(plStringView sSharedName, plUInt64 uiSize, Mode mode)
Attempts to open or create the given shared memory block addressed by szSharedName.
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
Definition MemoryMappedFile_NoImpl.h:9
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54