-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.c
49 lines (38 loc) · 1.02 KB
/
test.c
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
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include "xmempool.h"
#define TEST_COUNT 4096
typedef struct test_struct {
int id;
char str[16];
} test_struct;
void generate_str(char* str) {
str[15] = 0;
for (int i = 0; i < 15; i++) {
str[i] = (rand() % 26) + 'a'; // NOLINT: runtime/threadsafe_fn
}
}
void print_test_struct(test_struct* test) {
printf("%d [0x%8X]: %s\n", test->id, (int)test, test->str);
}
int main() {
xmem_pool_handle pool = xmem_create_pool(sizeof(test_struct));
test_struct* test_array[TEST_COUNT];
for (int i = 0; i < TEST_COUNT; i++) {
test_array[i] = (test_struct*)xmem_alloc(pool);
test_array[i]->id = i;
generate_str(test_array[i]->str);
print_test_struct(test_array[i]);
}
for (int i = 0; i < TEST_COUNT / 2; i++) {
xmem_free(pool, (char*)test_array[i]);
}
xmem_print_info(pool);
printf("\n");
for (int i = TEST_COUNT / 2; i < TEST_COUNT; i++) {
xmem_free(pool, (char*)test_array[i]);
}
xmem_print_info(pool);
xmem_destroy_pool(pool);
return 0;
}