diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-07 16:15:20 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-07 16:15:20 +0300 |
commit | 456d3cc85e9f408341b12eb0d4f2c3a925855e8c (patch) | |
tree | 7eef9a785facb9cf251d292d1bb72a062e45e935 /source/blender/blenlib/tests/BLI_linear_allocator_test.cc | |
parent | 84da76a96c5c2b59aeb67fa905398f656af25649 (diff) |
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.
Diffstat (limited to 'source/blender/blenlib/tests/BLI_linear_allocator_test.cc')
-rw-r--r-- | source/blender/blenlib/tests/BLI_linear_allocator_test.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_linear_allocator_test.cc b/source/blender/blenlib/tests/BLI_linear_allocator_test.cc index a35fbf70711..95156ae5c0c 100644 --- a/source/blender/blenlib/tests/BLI_linear_allocator_test.cc +++ b/source/blender/blenlib/tests/BLI_linear_allocator_test.cc @@ -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 |