mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Removes unused pointer from the allocate function
Also allows to compare ProxyAllocator. For example, it might be required for containers to compare iterators.
This commit is contained in:
parent
53ff6f0d50
commit
e4de94415e
4 changed files with 29 additions and 17 deletions
|
|
@ -126,7 +126,7 @@ public:
|
|||
m_Blocks.emplace_back();
|
||||
}
|
||||
|
||||
void* allocate(size_t n, const void*, size_t alignment)
|
||||
void* allocate(size_t n, size_t alignment)
|
||||
{
|
||||
// Safely handle zero-sized allocations (happens with GCC STL - see ticket #909).
|
||||
if (n == 0)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
T* allocate(size_t n)
|
||||
{
|
||||
return static_cast<T*>(allocator->allocate(n * sizeof(T), nullptr, alignof(T)));
|
||||
return static_cast<T*>(allocator->allocate(n * sizeof(T), alignof(T)));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, const size_t n)
|
||||
|
|
@ -102,7 +102,7 @@ public:
|
|||
|
||||
T* allocate(size_t n)
|
||||
{
|
||||
return static_cast<T*>(allocator.allocate(n * sizeof(T), nullptr, alignof(T)));
|
||||
return static_cast<T*>(allocator.allocate(n * sizeof(T), alignof(T)));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, const size_t n)
|
||||
|
|
@ -110,6 +110,18 @@ public:
|
|||
return allocator.deallocate(static_cast<void*>(ptr), n * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
bool operator==(const ProxyAllocator<V, Backend>& other) const
|
||||
{
|
||||
return std::addressof(allocator) == std::addressof(other.allocator);
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
bool operator!=(const ProxyAllocator<V, Backend>& other) const
|
||||
{
|
||||
return std::addressof(allocator) != std::addressof(other.allocator);
|
||||
}
|
||||
|
||||
private:
|
||||
Backend& allocator;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,46 +31,46 @@ public:
|
|||
void test_allocate()
|
||||
{
|
||||
Allocators::DynamicArena<100> testArena;
|
||||
u8* p = static_cast<u8*>(testArena.allocate(10, nullptr, 1));
|
||||
u8* p = static_cast<u8*>(testArena.allocate(10, 1));
|
||||
TS_ASSERT(p != nullptr);
|
||||
void* p2 = testArena.allocate(10, nullptr, 1);
|
||||
void* p2 = testArena.allocate(10, 1);
|
||||
TS_ASSERT(p + 10 == p2);
|
||||
|
||||
void* p3 = testArena.allocate(80, nullptr, 1);
|
||||
void* p3 = testArena.allocate(80, 1);
|
||||
TS_ASSERT(p + 20 == p3);
|
||||
|
||||
void* p4 = testArena.allocate(100, nullptr, 1);
|
||||
void* p4 = testArena.allocate(100, 1);
|
||||
TS_ASSERT(p4 != nullptr);
|
||||
|
||||
void* p5 = testArena.allocate(1, nullptr, 1);
|
||||
void* p5 = testArena.allocate(1, 1);
|
||||
TS_ASSERT(p5 != nullptr);
|
||||
|
||||
void* p6 = testArena.allocate(100, nullptr, 1);
|
||||
void* p6 = testArena.allocate(100, 1);
|
||||
TS_ASSERT(p6 != nullptr);
|
||||
|
||||
void* p7 = testArena.allocate(0, nullptr, 1);
|
||||
void* p7 = testArena.allocate(0, 1);
|
||||
TS_ASSERT(p7 != nullptr);
|
||||
}
|
||||
|
||||
void test_alignment()
|
||||
{
|
||||
Allocators::DynamicArena<100> testArena;
|
||||
u8* p = static_cast<u8*>(testArena.allocate(4, nullptr, 1));
|
||||
u8* p = static_cast<u8*>(testArena.allocate(4, 1));
|
||||
TS_ASSERT(p != nullptr);
|
||||
|
||||
u8* p2 = static_cast<u8*>(testArena.allocate(1, nullptr, 8));
|
||||
u8* p2 = static_cast<u8*>(testArena.allocate(1, 8));
|
||||
TS_ASSERT_EQUALS(p + 8, p2);
|
||||
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, nullptr, 8));
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, 8));
|
||||
TS_ASSERT_EQUALS(p + 16, p2);
|
||||
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, nullptr, 8));
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, 8));
|
||||
TS_ASSERT_EQUALS(p + 24, p2);
|
||||
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, nullptr, 2));
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, 2));
|
||||
TS_ASSERT_EQUALS(p + 26, p2);
|
||||
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, nullptr, 8));
|
||||
p2 = static_cast<u8*>(testArena.allocate(1, 8));
|
||||
TS_ASSERT_EQUALS(p + 32, p2);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
Release();
|
||||
}
|
||||
|
||||
void* allocate(std::size_t n, void*, std::size_t alignment)
|
||||
void* allocate(std::size_t n, std::size_t alignment)
|
||||
{
|
||||
m_Size = ROUND_UP(m_Size, alignment);
|
||||
if (m_Size + n > m_Capacity)
|
||||
|
|
|
|||
Loading…
Reference in a new issue