Generated on for Gecode by doxygen 1.17.0
main.cpp
Go to the documentation of this file.
1#include "boundary.hh"
2#include <cstdlib>
3#include <cstring>
4#include <thread>
5#ifdef CHECK_HOST_MIMALLOC
6#include <mimalloc.h>
7#endif
8
9#if GECODE_EXPECT_MIMALLOC && !defined(GECODE_MIMALLOC)
10#error "Expected mimalloc-enabled installed headers"
11#elif !GECODE_EXPECT_MIMALLOC && defined(GECODE_MIMALLOC)
12#error "Expected system-allocator installed headers"
13#endif
14
15int main(void) {
16 void* p = Gecode::heap.ralloc(256);
17#ifdef CHECK_HOST_MIMALLOC
18 void* host = mi_malloc(256);
19 void* system = std::malloc(256);
20 bool isolated = !mi_is_in_heap_region(p) && mi_is_in_heap_region(host);
21#if GECODE_HOST_MIMALLOC_OVERRIDE
22 isolated = isolated && mi_is_in_heap_region(system);
23#else
24 isolated = isolated && !mi_is_in_heap_region(system);
25#endif
26 mi_free(host);
27 std::free(system);
28 if (!isolated)
29 return 1;
30#endif
31 std::memset(p,0x5a,256);
32 std::thread resize([&] { p = boundary_realloc(p,16384); });
33 resize.join();
34 for (int i=0; i<256; i++)
35 if (static_cast<unsigned char*>(p)[i] != 0x5a)
36 return 2;
37#ifdef CHECK_HOST_MIMALLOC
38 if (mi_is_in_heap_region(p))
39 return 3;
40#endif
41 std::thread release([&] { boundary_free(p); });
42 release.join();
43 std::thread allocate([&] { p = boundary_alloc(1024); });
44 allocate.join();
45 p = Gecode::heap.rrealloc(p,4096);
46 Gecode::heap.rfree(p);
47
48 return 0;
49}
void * boundary_realloc(void *p, size_t n)
Definition boundary.cpp:6
void * boundary_alloc(size_t n)
Definition boundary.cpp:3
void boundary_free(void *p)
Definition boundary.cpp:9
Heap heap
The single global heap.
Definition heap.cpp:44
int main(void)
Definition main.cpp:15