| 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 | { |
nothing calls this directly
no test coverage detected