From e59cf7b09e7388d369e8d2bf73501cde79c28708 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 8 Apr 2021 16:43:58 +0200 Subject: Squashed 'EASTL/' content from commit fad5471 git-subtree-dir: EASTL git-subtree-split: fad54717f8e4ebb13b20095da7efd07a53af0f10 --- source/fixed_pool.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 source/fixed_pool.cpp (limited to 'source/fixed_pool.cpp') diff --git a/source/fixed_pool.cpp b/source/fixed_pool.cpp new file mode 100644 index 0000000..73b9be0 --- /dev/null +++ b/source/fixed_pool.cpp @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) Electronic Arts Inc. All rights reserved. +/////////////////////////////////////////////////////////////////////////////// + + +#include +#include + + + +namespace eastl +{ + + + EASTL_API void fixed_pool_base::init(void* pMemory, size_t memorySize, size_t nodeSize, + size_t alignment, size_t /*alignmentOffset*/) + { + // To do: Support alignmentOffset. + + #if EASTL_FIXED_SIZE_TRACKING_ENABLED + mnCurrentSize = 0; + mnPeakSize = 0; + #endif + + if(pMemory) + { + // Assert that alignment is a power of 2 value (e.g. 1, 2, 4, 8, 16, etc.) + EASTL_ASSERT((alignment & (alignment - 1)) == 0); + + // Make sure alignment is a valid value. + if(alignment < 1) + alignment = 1; + + mpNext = (Link*)(((uintptr_t)pMemory + (alignment - 1)) & ~(alignment - 1)); + memorySize -= (uintptr_t)mpNext - (uintptr_t)pMemory; + pMemory = mpNext; + + // The node size must be at least as big as a Link, which itself is sizeof(void*). + if(nodeSize < sizeof(Link)) + nodeSize = ((sizeof(Link) + (alignment - 1))) & ~(alignment - 1); + + // If the user passed in a memory size that wasn't a multiple of the node size, + // we need to chop down the memory size so that the last node is not a whole node. + memorySize = (memorySize / nodeSize) * nodeSize; + + mpCapacity = (Link*)((uintptr_t)pMemory + memorySize); + mpHead = NULL; + mnNodeSize = nodeSize; + } + } + + +} // namespace eastl + + + + + + + + + + + + + + + + + -- cgit v1.2.3