MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Allocate

Method Allocate

Source/Engine/Core/Memory/Allocation.cpp:25–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25void* ArenaAllocator::Allocate(uint64 size, uint64 alignment)
26{
27 if (size == 0)
28 return nullptr;
29 if (alignment < PLATFORM_MEMORY_ALIGNMENT)
30 alignment = PLATFORM_MEMORY_ALIGNMENT;
31
32 // Find the first page that has some space left
33 Page* page = _first;
34 while (page && page->Offset + size + alignment > page->Size)
35 page = page->Next;
36
37 // Create a new page if need to
38 if (!page)
39 {
40 uint64 pageSize = Math::Max<uint64>(_pageSize, size + alignment + sizeof(Page));
41#if COMPILE_WITH_PROFILER
42 ProfilerMemory::OnGroupUpdate(ProfilerMemory::Groups::MallocArena, (int64)pageSize, 1);
43#endif
44 page = (Page*)Allocator::Allocate(pageSize);
45 page->Next = _first;
46 page->Offset = sizeof(Page);
47 page->Size = (uint32)pageSize;
48 _first = page;
49 }
50
51 // Allocate within a page
52 page->Offset = Math::AlignUp(page->Offset, (uint32)alignment);
53 void* mem = (byte*)page + page->Offset;
54 page->Offset += (uint32)size;
55
56 return mem;
57}
58
59void ConcurrentArenaAllocator::Free()
60{

Callers 15

ImportMethod · 0.45
CreateMethod · 0.45
ImportMethod · 0.45
ImportMethod · 0.45
SaveMethod · 0.45
LoadAssetChunkMethod · 0.45
BindMethod · 0.45
MoveToEmptyFunction · 0.45
PushBackMethod · 0.45
BitArrayMethod · 0.45
BitArray.hFile · 0.45
SwapFunction · 0.45

Calls 7

AlignUpFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
AtomicReadFunction · 0.50
InterlockedAddFunction · 0.50
AtomicStoreFunction · 0.50

Tested by

no test coverage detected