Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
LargeMemoryData.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/LockFreeList.h"
6#include "CoreTypes.h"
7
8#include <atomic>
9
10template <class T, int TPaddingForCacheContention> class TLockFreePointerListUnordered;
11
12/**
13* Data storage for the large memory reader and writer.
14*/
15
17{
18public:
19
20 explicit FLargeMemoryData(const int64 PreAllocateBytes = 0);
22
23 /** Write data at the given offset. Returns true if the data was written. */
24 bool Write(void* InData, int64 InOffset, int64 InNum);
25
26 /** Append data at the given offset. */
27 FORCEINLINE void Append(void* InData, int64 InNum)
28 {
29 Write(InData, NumBytes, InNum);
30 }
31
32 /** Read data at the given offset. Returns true if the data was read. */
33 bool Read(void* OutData, int64 InOffset, int64 InNum) const;
34
35 /** Gets the size of the data written. */
36 FORCEINLINE int64 GetSize() const
37 {
38 return NumBytes;
39 }
40
41 /** Returns the written data. */
43 {
44 return Data;
45 }
46
47 /** Returns the written data. */
48 FORCEINLINE const uint8* GetData() const
49 {
50 return Data;
51 }
52
53 /** Releases ownership of the written data. */
55
56 /** Check whether data is allocated or if the ownership was released. */
57 bool HasData() const
58 {
59 return Data != nullptr;
60 }
61
62 void Reserve(int64 Size);
63
64private:
65
66 /** Non-copyable */
69
70 /** Memory owned by this archive. Ownership can be released by calling ReleaseOwnership() */
71 uint8* Data;
72
73 /** Number of bytes currently written to our data buffer */
74 int64 NumBytes;
75
76 /** Number of bytes currently allocated for our data buffer */
77 int64 MaxBytes;
78
79 /** Resizes the data buffer to at least NumBytes with some slack */
80 void GrowBuffer();
81};
82
83/**
84* Pooled storage of FLargeMemoryData instances, allowing allocation-free and lock-free access.
85*/
87{
88public:
91 FLargeMemoryData& Get() { return *Data; }
92private:
94 static TLockFreePointerListUnordered<FLargeMemoryData, 0> FreeList;
95 static std::atomic<int32> FreeListLength;
96};
#define FORCEINLINE
Definition Platform.h:644
void Reserve(int64 Size)
FORCEINLINE uint8 * GetData()
bool Write(void *InData, int64 InOffset, int64 InNum)
bool Read(void *OutData, int64 InOffset, int64 InNum) const
uint8 * ReleaseOwnership()
FORCEINLINE const uint8 * GetData() const
FORCEINLINE int64 GetSize() const
FORCEINLINE void Append(void *InData, int64 InNum)
bool HasData() const
FLargeMemoryData(const int64 PreAllocateBytes=0)
FLargeMemoryData & operator=(const FLargeMemoryData &)=delete
FLargeMemoryData(const FLargeMemoryData &)=delete
static std::atomic< int32 > FreeListLength
static TLockFreePointerListUnordered< FLargeMemoryData, 0 > FreeList
FLargeMemoryData & Get()
FLargeMemoryData * Data
Definition json.hpp:4518