test/test_basic_mempool.cpp

Tue, 04 Oct 2022 19:25:07 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 04 Oct 2022 19:25:07 +0200
changeset 591
7df0bcaecffa
parent 572
f0f99dd06d9f
permissions
-rw-r--r--

fix over-optimization of strstr

1. it's actually less performant to frequently read bytes
from an array instead of using the native word length
2. the SBO buffer should be local and not static to allow
multi-threading usage

571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/basic_mempool.h"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include <gtest/gtest.h>
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 class CxBasicMempool : public ::testing::Test {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 protected:
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 CxMempool *pool = nullptr;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 void TearDown() override {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 if (pool != nullptr) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 cxMempoolDestroy(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 };
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 TEST_F(CxBasicMempool, Create) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
45 pool = cxBasicMempoolCreate(16);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 ASSERT_NE(pool->allocator, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 ASSERT_NE(pool->cl, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 EXPECT_NE(pool->cl->destroy, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 ASSERT_NE(pool->allocator->cl, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 EXPECT_EQ(pool->allocator->data, pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 EXPECT_NE(pool->allocator->cl->malloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 EXPECT_NE(pool->allocator->cl->calloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 EXPECT_NE(pool->allocator->cl->realloc, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 EXPECT_NE(pool->allocator->cl->free, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 EXPECT_EQ(basic_pool->size, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 EXPECT_EQ(basic_pool->ndata, 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 EXPECT_NE(basic_pool->data, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 TEST_F(CxBasicMempool, malloc) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
63 pool = cxBasicMempoolCreate(4);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 EXPECT_EQ(basic_pool->ndata, 2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 EXPECT_EQ(basic_pool->size, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 EXPECT_EQ(basic_pool->ndata, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 EXPECT_EQ(basic_pool->size, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 EXPECT_NE(cxMalloc(pool->allocator, sizeof(int)), nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 EXPECT_EQ(basic_pool->ndata, 6);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 EXPECT_GE(basic_pool->size, 6);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 TEST_F(CxBasicMempool, calloc) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
80 pool = cxBasicMempoolCreate(4);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 auto test = (int *) cxCalloc(pool->allocator, 2, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 ASSERT_NE(test, nullptr);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 EXPECT_EQ(test[0], 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 EXPECT_EQ(test[1], 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 static unsigned test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 static void test_destructor([[maybe_unused]] void *mem) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 test_destructor_called++;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 TEST_F(CxBasicMempool, destructor) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
95 pool = cxBasicMempoolCreate(4);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 auto data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 *((int *) data) = 13;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 EXPECT_EQ(*((int *) data), 13);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 cxFree(pool->allocator, data);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 EXPECT_EQ(test_destructor_called, 1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 cxMempoolDestroy(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 pool = nullptr;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 EXPECT_EQ(test_destructor_called, 2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 TEST_F(CxBasicMempool, realloc) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
111 pool = cxBasicMempoolCreate(4);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 auto data = cxMalloc(pool->allocator, sizeof(int));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 *((int *) data) = 13;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 cxMempoolSetDestructor(pool, data, test_destructor);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 void *rdata = data;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 unsigned n = 1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 while (rdata == data) {
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 n <<= 1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 ASSERT_LT(n, 65536); // eventually the memory should be moved elsewhere
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 rdata = cxRealloc(pool->allocator, data, n * sizeof(intptr_t));
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 EXPECT_EQ(*((int *) rdata), 13);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 // test if destructor is still intact
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 test_destructor_called = 0;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 cxFree(pool->allocator, rdata);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 EXPECT_EQ(test_destructor_called, 1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 }
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 TEST_F(CxBasicMempool, free) {
572
f0f99dd06d9f #201 - remove dangerous allocator config
Mike Becker <universe@uap-core.de>
parents: 571
diff changeset
133 pool = cxBasicMempoolCreate(4);
571
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 auto basic_pool = reinterpret_cast<cx_basic_mempool_s *>(pool);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 void *mem1;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 void *mem2;
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 mem1 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 cxFree(pool->allocator, mem1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 EXPECT_EQ(basic_pool->ndata, 0);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 mem1 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 mem2 = cxMalloc(pool->allocator, 16);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 EXPECT_EQ(basic_pool->ndata, 5);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 cxFree(pool->allocator, mem1);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 EXPECT_EQ(basic_pool->ndata, 4);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 cxFree(pool->allocator, mem2);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 EXPECT_EQ(basic_pool->ndata, 3);
f83583a0bbac #201 - add mempool implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }

mercurial