mimalloc/test/main-override.cpp

72 lines
1.0 KiB
C++
Raw Normal View History

2019-06-19 16:26:12 -07:00
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
2019-06-19 16:26:12 -07:00
#include <mimalloc.h>
#include <new>
2019-06-19 16:26:12 -07:00
static void* p = malloc(8);
void free_p() {
free(p);
return;
}
class Test {
private:
int i;
public:
Test(int x) { i = x; }
~Test() { }
};
2019-07-22 01:36:16 -07:00
int main() {
2019-11-02 10:30:16 -07:00
mi_stats_reset(); // ignore earlier allocations
2019-06-19 16:26:12 -07:00
atexit(free_p);
void* p1 = malloc(78);
2019-07-22 01:36:16 -07:00
void* p2 = mi_malloc_aligned(16,24);
free(p1);
2019-06-19 16:26:12 -07:00
p1 = malloc(8);
2019-07-22 01:36:16 -07:00
char* s = mi_strdup("hello\n");
2019-09-01 17:21:58 -07:00
/*
char* s = _strdup("hello\n");
char* buf = NULL;
size_t len;
_dupenv_s(&buf,&len,"MIMALLOC_VERBOSE");
mi_free(buf);
*/
mi_free(p2);
2019-06-19 16:26:12 -07:00
p2 = malloc(16);
p1 = realloc(p1, 32);
free(p1);
2019-10-17 09:21:20 -07:00
free(p2);
mi_free(s);
Test* t = new Test(42);
delete t;
t = new (std::nothrow) Test(42);
2019-07-22 10:27:14 -07:00
delete t;
mi_stats_print(NULL);
2019-07-18 19:52:29 -07:00
return 0;
2019-06-19 16:26:12 -07:00
}
class Static {
private:
void* p;
public:
Static() {
p = malloc(64);
return;
}
~Static() {
free(p);
return;
}
};
static Static s = Static();