MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / restore

Function restore

TheForceEngine/TFE_Memory/chunkedArray.cpp:60–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 }
59
60 ChunkedArray* restore(FileStream* file, MemoryRegion* region)
61 {
62 assert(file && region);
63 ChunkedArray* arr = (ChunkedArray*)region_alloc(region, sizeof(ChunkedArray));
64 memset(arr, 0, sizeof(ChunkedArray));
65
66 size_t size = size_t(&arr->chunks) - sizeof(arr);
67 file->readBuffer(arr, (u32)size);
68
69 arr->chunks = (u8**)region_realloc(region, arr->chunks, sizeof(u8*) * arr->chunkCount);
70 const u32 chunkAllocSize = arr->elemPerChunk * arr->elemSize;
71 for (u32 i = 0; i < arr->chunkCount; i++)
72 {
73 arr->chunks[i] = (u8*)region_alloc(region, chunkAllocSize);
74 file->read(arr->chunks[i], chunkAllocSize);
75 }
76
77 arr->freeSlots = (u8**)region_realloc(region, arr->freeSlots, sizeof(u8**) * arr->freeSlotCapacity);
78 for (u32 i = 0; i < arr->freeSlotCount; i++)
79 {
80 s32 freeSlotIndex;
81 file->read(&freeSlotIndex);
82 if (freeSlotIndex >= 0)
83 {
84 arr->freeSlots[i] = arr->chunks[freeSlotIndex];
85 }
86 else
87 {
88 arr->freeSlots[i] = nullptr;
89 }
90 }
91 return arr;
92 }
93
94 ChunkedArray* createChunkedArray(u32 elemSize, u32 elemPerChunk, u32 initChunkCount, MemoryRegion* region)
95 {

Callers

nothing calls this directly

Calls 4

region_allocFunction · 0.85
region_reallocFunction · 0.85
readBufferMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected