forked from foonathan/memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaligned_allocator.cpp
More file actions
33 lines (24 loc) · 996 Bytes
/
Copy pathaligned_allocator.cpp
File metadata and controls
33 lines (24 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (C) 2015-2016 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include "aligned_allocator.hpp"
#include <catch.hpp>
#include "detail/align.hpp"
#include "allocator_storage.hpp"
#include "memory_stack.hpp"
using namespace foonathan::memory;
TEST_CASE("aligned_allocator", "[adapter]")
{
using allocator_t = aligned_allocator<allocator_reference<memory_stack<>>>;
memory_stack<> stack(1024);
stack.allocate(3, 1); // manual misalign
allocator_t alloc(4u, stack);
REQUIRE(alloc.min_alignment() == 4u);
auto mem1 = alloc.allocate_node(16u, 1u);
REQUIRE(detail::align_offset(mem1, 4u) == 0u);
auto mem2 = alloc.allocate_node(16u, 8u);
REQUIRE(detail::align_offset(mem2, 4u) == 0u);
REQUIRE(detail::align_offset(mem2, 8u) == 0u);
alloc.deallocate_node(mem2, 16u, 8u);
alloc.deallocate_node(mem1, 16u, 1u);
}