fixed-pool.pmr.cpp

 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
34
35
36
37
38
39
40
41
42
#include <felspar/memory/fixed-pool.pmr.hpp>
#include <felspar/test.hpp>


namespace {


    auto const suite = felspar::testsuite("fixed-pool.pmr");


    auto const s = suite.test("small", [](auto check) {
        felspar::memory::fixed_pool fp{
                512, felspar::pmr::new_delete_resource()};

        void *a1 = fp.allocate(100);
        void *a2 = fp.allocate(100);
        check(a1) != a2;
        fp.deallocate(a1, 100);
        fp.deallocate(a2, 100);

        void *a3 = fp.allocate(200);
        check(a3) == a2;
        fp.deallocate(a3, 200);
    });


    auto const b = suite.test("big", [](auto check) {
        felspar::memory::fixed_pool fp{
                512, felspar::pmr::new_delete_resource()};

        void *a1 = fp.allocate(1000);
        void *a2 = fp.allocate(1000);
        check(a1) != a2;
        fp.deallocate(a1, 1000);
        fp.deallocate(a2, 1000);

        void *a3 = fp.allocate(2000);
        fp.deallocate(a3, 2000);
    });


}