mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 11:34:38 +03:00
initial checkin
This commit is contained in:
parent
23b4e65faa
commit
26a874eb3f
41 changed files with 11897 additions and 0 deletions
29
test/CMakeLists.txt
Normal file
29
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(mimalloc-test C CXX)
|
||||
|
||||
# Set default build type
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
|
||||
message(STATUS "No build type selected, default to *** Debug ***")
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
else()
|
||||
message(STATUS "No build type selected, default to *** Release ***")
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Import mimalloc (if installed)
|
||||
find_package(mimalloc 1.0 REQUIRED)
|
||||
|
||||
# Tests
|
||||
add_executable(static-override main-override.c)
|
||||
target_link_libraries(static-override PUBLIC mimalloc-static)
|
||||
|
||||
add_executable(static-override-cxx main-override.cpp)
|
||||
target_link_libraries(static-override-cxx PUBLIC mimalloc-static)
|
||||
|
||||
add_executable(dynamic-override main-override.c)
|
||||
target_link_libraries(dynamic-override PUBLIC mimalloc)
|
||||
|
||||
add_executable(dynamic-override-cxx main-override.cpp)
|
||||
target_link_libraries(dynamic-override-cxx PUBLIC mimalloc)
|
25
test/main-override.c
Normal file
25
test/main-override.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mimalloc.h>
|
||||
|
||||
|
||||
int main() {
|
||||
mi_stats_reset();
|
||||
void* p1 = malloc(78);
|
||||
void* p2 = malloc(24);
|
||||
free(p1);
|
||||
p1 = malloc(8);
|
||||
char* s = strdup("hello\n");
|
||||
free(p2);
|
||||
p2 = malloc(16);
|
||||
p1 = realloc(p1, 32);
|
||||
free(p1);
|
||||
free(p2);
|
||||
free(s);
|
||||
mi_collect(true);
|
||||
mi_stats_print(NULL);
|
||||
return 0;
|
||||
}
|
48
test/main-override.cpp
Normal file
48
test/main-override.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mimalloc.h>
|
||||
|
||||
static void* p = malloc(8);
|
||||
|
||||
void free_p() {
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
int main() {
|
||||
mi_stats_reset();
|
||||
atexit(free_p);
|
||||
void* p1 = malloc(78);
|
||||
void* p2 = malloc(24);
|
||||
free(p1);
|
||||
p1 = malloc(8);
|
||||
char* s = mi_strdup("hello\n");
|
||||
free(p2);
|
||||
p2 = malloc(16);
|
||||
p1 = realloc(p1, 32);
|
||||
free(p1);
|
||||
free(p2);
|
||||
free(s);
|
||||
mi_collect(true);
|
||||
mi_stats_print(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class Static {
|
||||
private:
|
||||
void* p;
|
||||
public:
|
||||
Static() {
|
||||
p = malloc(64);
|
||||
return;
|
||||
}
|
||||
~Static() {
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
static Static s = Static();
|
35
test/main.c
Normal file
35
test/main.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <mimalloc.h>
|
||||
|
||||
void test_heap(void* p_out) {
|
||||
mi_heap_t* heap = mi_heap_new();
|
||||
void* p1 = mi_heap_malloc(heap,32);
|
||||
void* p2 = mi_heap_malloc(heap,48);
|
||||
mi_free(p_out);
|
||||
mi_heap_destroy(heap);
|
||||
//mi_heap_delete(heap); mi_free(p1); mi_free(p2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
void* p1 = mi_malloc(16);
|
||||
void* p2 = mi_malloc(1000000);
|
||||
mi_free(p1);
|
||||
mi_free(p2);
|
||||
p1 = mi_malloc(16);
|
||||
p2 = mi_malloc(16);
|
||||
mi_free(p1);
|
||||
mi_free(p2);
|
||||
|
||||
test_heap(mi_malloc(32));
|
||||
|
||||
p1 = mi_malloc_aligned(64, 16);
|
||||
p2 = mi_malloc_aligned(160,24);
|
||||
mi_free(p2);
|
||||
mi_free(p1);
|
||||
|
||||
mi_collect(true);
|
||||
mi_stats_print(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
17
test/main.cpp
Normal file
17
test/main.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <rcmalloc.h>
|
||||
|
||||
int main() {
|
||||
void* p1 = rc_malloc(16);
|
||||
void* p2 = rc_malloc(16);
|
||||
rc_free(p1);
|
||||
rc_free(p2);
|
||||
p1 = rc_malloc(16);
|
||||
p2 = rc_malloc(16);
|
||||
rc_free(p1);
|
||||
rc_free(p2);
|
||||
rc_collect(true);
|
||||
rc_stats_print();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue