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);
126 cout <<
"Foo Constructor" <<
endl;
135 cout <<
"Foo Destructor" <<
endl;
147 for (
int i = 0;
true; ++i)
154 cout <<
"Allocated " << i <<
" node" <<
endl;
159 chunks.reverse().for_each([
this] (
Foo * ptr)
161 cout <<
"Freeing " << ptr->
i <<
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.
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)
QuadTree - Hierarchical spatial index for 2D points.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
bool operator<(const Foo &r)
Foo(const char *data, int i)
unique_ptr< char[]> buffer
static constexpr size_t sz
Dynamic set implementations based on balanced binary search trees.