Skip to content

Commit 07286d8

Browse files
committed
Fixed Windows and Mac builds
1 parent e025ac5 commit 07286d8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/resource_manager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ struct IResearchMemoryManager : public IResourceManager {
9393
_current.fetch_add(value, std::memory_order_relaxed);
9494
} else {
9595
// we only want to perform the update if we don't exceed the limit!
96-
std::uint64_t cur = _current.load(std::memory_order_relaxed);
97-
std::uint64_t next;
96+
size_t cur = _current.load(std::memory_order_relaxed);
97+
size_t next;
9898
do {
9999
next = cur + value;
100100
if (IRS_UNLIKELY(next > _memoryLimit.load(std::memory_order_relaxed))) {

tests/memory/IResearchMemoryManager_tests.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,22 @@ TEST(IResearchMemoryLimitTest, memory_manager_smoke_test) {
7676

7777
// set limit
7878
auto memoryMgr = IResearchMemoryManager::GetInstance();
79-
memoryMgr->SetMemoryLimit(47);
79+
memoryMgr->SetMemoryLimit(39);
8080

8181
// allocate vector
8282
ManagedVector<uint64_t> vec;
8383
vec.push_back(10); // Allocate 8 bytes
8484
vec.push_back(11); // Allocate 16, Free previous 8, Copy both elements in the new array.
8585

86-
ASSERT_THROW(vec.push_back(12), std::bad_alloc); // Allocate 32 while holding previous 16, total 48 (bad_alloc)
86+
// Linux: Allocate 32 while holding previous 16, total 48 (bad_alloc)
87+
// Windows: Allocate 24 while holding previous 16, total 40 (bad_alloc)
88+
//
89+
// std::vector, on linux, doubles the size() when
90+
// there's not enough space to store the newly inserted item.
91+
// On Windows, it allocates the new memory only big enough to
92+
// store (size() + size() / 2) items.
93+
//
94+
ASSERT_THROW(vec.push_back(12), std::bad_alloc);
8795

8896
// Increase memory limit to accommodate the 3rd element.
8997
memoryMgr->SetMemoryLimit(48);

0 commit comments

Comments
 (0)