mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-28 22:05:40 +08:00
Merge branch 'dev-debug' of https://github.com/microsoft/mimalloc into dev-debug
This commit is contained in:
commit
6e08b0c0c8
@ -7,7 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mimalloc.h>
|
#include <mimalloc.h>
|
||||||
#include <mimalloc-new-delete.h>
|
// #include <mimalloc-new-delete.h>
|
||||||
#include <mimalloc-override.h>
|
#include <mimalloc-override.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -18,14 +18,16 @@ static void msleep(unsigned long msecs) { Sleep(msecs); }
|
|||||||
static void msleep(unsigned long msecs) { usleep(msecs * 1000UL); }
|
static void msleep(unsigned long msecs) { usleep(msecs * 1000UL); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void heap_no_delete();
|
static void heap_no_delete();
|
||||||
void heap_late_free();
|
static void heap_late_free();
|
||||||
void various_tests();
|
static void various_tests();
|
||||||
|
static void dangling_ptr_write();
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
mi_stats_reset(); // ignore earlier allocations
|
mi_stats_reset(); // ignore earlier allocations
|
||||||
// heap_no_delete(); // issue #202
|
// heap_no_delete(); // issue #202
|
||||||
// heap_late_free(); // issue #204
|
// heap_late_free(); // issue #204
|
||||||
|
// dangling_ptr_write();
|
||||||
various_tests();
|
various_tests();
|
||||||
mi_stats_print(NULL);
|
mi_stats_print(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
@ -46,11 +48,9 @@ public:
|
|||||||
~Test() { }
|
~Test() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
void dangling_ptr_write();
|
|
||||||
|
|
||||||
void various_tests() {
|
static void various_tests() {
|
||||||
atexit(free_p);
|
atexit(free_p);
|
||||||
//dangling_ptr_write();
|
|
||||||
void* p1 = malloc(78);
|
void* p1 = malloc(78);
|
||||||
void* p2 = mi_malloc_aligned(16,24);
|
void* p2 = mi_malloc_aligned(16,24);
|
||||||
free(p1);
|
free(p1);
|
||||||
@ -110,7 +110,7 @@ public:
|
|||||||
static Static s = Static();
|
static Static s = Static();
|
||||||
|
|
||||||
|
|
||||||
bool test_stl_allocator1() {
|
static bool test_stl_allocator1() {
|
||||||
std::vector<int, mi_stl_allocator<int> > vec;
|
std::vector<int, mi_stl_allocator<int> > vec;
|
||||||
vec.push_back(1);
|
vec.push_back(1);
|
||||||
vec.pop_back();
|
vec.pop_back();
|
||||||
@ -129,13 +129,13 @@ bool test_stl_allocator2() {
|
|||||||
|
|
||||||
|
|
||||||
// Issue #202
|
// Issue #202
|
||||||
void heap_no_delete_worker() {
|
static void heap_no_delete_worker() {
|
||||||
mi_heap_t* heap = mi_heap_new();
|
mi_heap_t* heap = mi_heap_new();
|
||||||
void* q = mi_heap_malloc(heap,1024);
|
void* q = mi_heap_malloc(heap,1024);
|
||||||
// mi_heap_delete(heap); // uncomment to prevent assertion
|
// mi_heap_delete(heap); // uncomment to prevent assertion
|
||||||
}
|
}
|
||||||
|
|
||||||
void heap_no_delete() {
|
static void heap_no_delete() {
|
||||||
auto t1 = std::thread(heap_no_delete_worker);
|
auto t1 = std::thread(heap_no_delete_worker);
|
||||||
t1.join();
|
t1.join();
|
||||||
}
|
}
|
||||||
@ -144,13 +144,13 @@ void heap_no_delete() {
|
|||||||
// Issue #204
|
// Issue #204
|
||||||
volatile void* global_p;
|
volatile void* global_p;
|
||||||
|
|
||||||
void t1main() {
|
static void t1main() {
|
||||||
mi_heap_t* heap = mi_heap_new();
|
mi_heap_t* heap = mi_heap_new();
|
||||||
global_p = mi_heap_malloc(heap, 1024);
|
global_p = mi_heap_malloc(heap, 1024);
|
||||||
mi_heap_delete(heap);
|
mi_heap_delete(heap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void heap_late_free() {
|
static void heap_late_free() {
|
||||||
auto t1 = std::thread(t1main);
|
auto t1 = std::thread(t1main);
|
||||||
|
|
||||||
msleep(2000);
|
msleep(2000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user