39# include <gsl/gsl_rng.h>
40# include <gtest/gtest.h>
47using namespace testing;
51 static constexpr size_t sz = 1021;
62 void * ptr = arena.
alloc(sz + 1);
68 void * ptr = arena.alloc(10);
71 arena.dealloc(ptr, 10);
78 void * ptr = arena.alloc(sz);
81 ASSERT_EQ((
void*) ((
char*) ptr + sz), arena.end_addr());
85 void *
ptr1 = arena.alloc(1);
92 const char*
env_seed = std::getenv(
"ALEPH_TEST_SEED");
105 const char *
addr =
static_cast<const char *
>(arena.alloc(
size));
110 cout <<
"Available size = " << arena.available_size() <<
endl
111 <<
"Last requested size = " <<
size <<
endl;
113 ASSERT_EQ(arena.alloc(arena.available_size() + 1),
nullptr);
147 for (
int i = 0;
true; ++i)
154 cout <<
"Allocated " << i <<
" node" <<
endl;
174 constexpr size_t n = 1024;
178 for (
int i = 0;
true; ++i)
182 int * ptr = tree.
insert(i);
186 cout <<
"Allocated " << i <<
" node" <<
endl;
188 catch (bad_alloc & e)
190 cout <<
"Arena limit reached" <<
endl
197 cout <<
"Inserted " << tree.
size() <<
" entries" <<
endl;
204 ::testing::InitGoogleTest(&
argc,
argv);
Memory arena for fast bulk allocations.
TEST_F(StaticArenaFixture, simple_fail)
static unsigned long get_seed()
Arena allocator for fast bump-pointer allocation.
void * alloc(const size_t size) noexcept
Allocate raw memory from the arena.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
DynList & reverse() noexcept
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
size_t arena_allocated_size() const noexcept
Returns the allocated size from the arena (0 if not using arena)
size_t arena_available_size() const noexcept
Returns the available size in the arena (0 if not using arena)
size_t size() const noexcept
Count the number of elements of the list.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
DynList< T > maps(const C &c, Op op)
Classic map operation.
bool operator<(const Foo rhs) const
Foo(const char *data, int i)
unique_ptr< char[]> buffer
static constexpr size_t sz
Dynamic set implementations based on balanced binary search trees.