BLI: reduce wasted memory in linear allocator
The main change is that large allocations are done separately now. Also, buffers that small allocations are packed into, have a maximum size now. Using larger buffers does not really provider performance benefits, but increases wasted memory.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* Apache License, Version 2.0 */
|
||||
|
||||
#include "BLI_linear_allocator.hh"
|
||||
#include "BLI_rand.hh"
|
||||
#include "BLI_strict_flags.h"
|
||||
#include "testing/testing.h"
|
||||
|
||||
@@ -115,4 +116,24 @@ TEST(linear_allocator, ConstructArrayCopy)
|
||||
EXPECT_EQ(span2[2], 3);
|
||||
}
|
||||
|
||||
TEST(linear_allocator, AllocateLarge)
|
||||
{
|
||||
LinearAllocator<> allocator;
|
||||
void *buffer1 = allocator.allocate(1024 * 1024, 8);
|
||||
void *buffer2 = allocator.allocate(1024 * 1024, 8);
|
||||
EXPECT_NE(buffer1, buffer2);
|
||||
}
|
||||
|
||||
TEST(linear_allocator, ManyAllocations)
|
||||
{
|
||||
LinearAllocator<> allocator;
|
||||
RandomNumberGenerator rng;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
int size = rng.get_int32(10000);
|
||||
int alignment = 1 << (rng.get_int32(7));
|
||||
void *buffer = allocator.allocate(size, alignment);
|
||||
EXPECT_NE(buffer, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
||||
Reference in New Issue
Block a user