summaryrefslogtreecommitdiffstats
path: root/Common/src
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-02-13 19:29:06 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-02-13 19:29:06 +0000
commit208ca9fafdbf53bb41213834bba697cad2b4ff5d (patch)
treed8739487826900bf9de331d100f6a26ffed27f94 /Common/src
parentUpdated TraceLineThroughGrid test plus some minor comments clean-up (diff)
downloadDiligentCore-208ca9fafdbf53bb41213834bba697cad2b4ff5d.tar.gz
DiligentCore-208ca9fafdbf53bb41213834bba697cad2b4ff5d.zip
FixedBlockMemoryAllocator: fixed issue with block size alignment by sizeof(void*)
Diffstat (limited to 'Common/src')
-rw-r--r--Common/src/FixedBlockMemoryAllocator.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/Common/src/FixedBlockMemoryAllocator.cpp b/Common/src/FixedBlockMemoryAllocator.cpp
index 8235edc0..bca872fa 100644
--- a/Common/src/FixedBlockMemoryAllocator.cpp
+++ b/Common/src/FixedBlockMemoryAllocator.cpp
@@ -26,11 +26,18 @@
*/
#include "pch.h"
+#include <algorithm>
#include "FixedBlockMemoryAllocator.hpp"
+#include "Align.hpp"
namespace Diligent
{
+static size_t AdjustBlockSize(size_t BlockSize)
+{
+ return Align(std::max(BlockSize, size_t{1}), sizeof(void*));
+}
+
FixedBlockMemoryAllocator::FixedBlockMemoryAllocator(IMemoryAllocator& RawMemoryAllocator,
size_t BlockSize,
Uint32 NumBlocksInPage) :
@@ -38,16 +45,13 @@ FixedBlockMemoryAllocator::FixedBlockMemoryAllocator(IMemoryAllocator& RawMemory
m_PagePool (STD_ALLOCATOR_RAW_MEM(MemoryPage, RawMemoryAllocator, "Allocator for vector<MemoryPage>")),
m_AvailablePages (STD_ALLOCATOR_RAW_MEM(size_t, RawMemoryAllocator, "Allocator for unordered_set<size_t>") ),
m_AddrToPageId (STD_ALLOCATOR_RAW_MEM(AddrToPageIdMapElem, RawMemoryAllocator, "Allocator for unordered_map<void*, size_t>")),
- m_RawMemoryAllocator{RawMemoryAllocator},
- m_BlockSize {BlockSize },
- m_NumBlocksInPage {NumBlocksInPage }
+ m_RawMemoryAllocator{RawMemoryAllocator },
+ m_BlockSize {AdjustBlockSize(BlockSize)},
+ m_NumBlocksInPage {NumBlocksInPage }
// clang-format on
{
- if (BlockSize > 0)
- {
- // Allocate one page
- CreateNewPage();
- }
+ // Allocate one page
+ CreateNewPage();
}
FixedBlockMemoryAllocator::~FixedBlockMemoryAllocator()
@@ -70,6 +74,7 @@ void FixedBlockMemoryAllocator::CreateNewPage()
void* FixedBlockMemoryAllocator::Allocate(size_t Size, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
{
+ Size = AdjustBlockSize(Size);
VERIFY(m_BlockSize == Size, "Requested size (", Size, ") does not match the block size (", m_BlockSize, ")");
std::lock_guard<std::mutex> LockGuard(m_Mutex);