-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8_1] Support mimalloc on macos/linux/windows, support jemalloc on linux
- Loading branch information
1 parent
d0b3956
commit 653bd9b
Showing
9 changed files
with
215 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
/****************************************************************************** | ||
* MODULE : Fast memory allocation using jemalloc | ||
* DESCRIPTION: | ||
* COPYRIGHT : (C) 2023-2024 jingkaimori | ||
******************************************************************************* | ||
* This software falls under the GNU general public license version 3 or later. | ||
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE | ||
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
******************************************************************************/ | ||
|
||
#include "assert.h" | ||
#include "fast_alloc.hpp" | ||
#include <jemalloc/jemalloc.h> | ||
|
||
int mem_used (); | ||
|
||
/*****************************************************************************/ | ||
// General purpose fast allocation routines | ||
/*****************************************************************************/ | ||
|
||
void* | ||
safe_malloc (size_t sz) { | ||
void* ptr= malloc (sz); | ||
|
||
if (ptr == NULL) { | ||
cerr << "Fatal error: out of memory\n"; | ||
abort (); | ||
} | ||
return ptr; | ||
} | ||
|
||
void* | ||
fast_alloc (size_t sz) { | ||
return safe_malloc (sz); | ||
} | ||
|
||
void | ||
fast_free (void* ptr, size_t sz) { | ||
free (ptr); | ||
} | ||
|
||
void* | ||
fast_new (size_t s) { | ||
return safe_malloc (s); | ||
} | ||
|
||
void | ||
fast_delete (void* ptr) { | ||
free (ptr); | ||
} | ||
|
||
/****************************************************************************** | ||
* Statistics | ||
******************************************************************************/ | ||
|
||
int | ||
mem_used () { | ||
cerr << "memory statistics is NOT IMPLEMENTED\n"; | ||
return 0; | ||
} | ||
|
||
void | ||
mem_info () { | ||
cout << "\n------- (NOT IMPLEMENTED) memory statistics -------\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
/****************************************************************************** | ||
* MODULE : Fast memory allocation using mimalloc | ||
* DESCRIPTION: | ||
* COPYRIGHT : (C) 2023-2024 jingkaimori | ||
******************************************************************************* | ||
* This software falls under the GNU general public license version 3 or later. | ||
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE | ||
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
******************************************************************************/ | ||
|
||
#include "assert.h" | ||
#include "basic.hpp" | ||
#include "fast_alloc.hpp" | ||
#include <mimalloc.h> | ||
|
||
/*****************************************************************************/ | ||
// General purpose fast allocation routines | ||
/*****************************************************************************/ | ||
|
||
void* | ||
safe_malloc (size_t sz) { | ||
void* ptr= mi_malloc (mi_good_size (sz)); | ||
if (ptr == NULL) { | ||
cerr << "Fatal error: out of memory\n"; | ||
abort (); | ||
} | ||
return ptr; | ||
} | ||
|
||
void* | ||
fast_alloc (size_t sz) { | ||
return safe_malloc (sz); | ||
} | ||
|
||
void | ||
fast_free (void* ptr, size_t sz) { | ||
mi_free (ptr); | ||
} | ||
|
||
void* | ||
fast_new (size_t s) { | ||
return safe_malloc (s); | ||
} | ||
|
||
void | ||
fast_delete (void* ptr) { | ||
mi_free (ptr); | ||
} | ||
|
||
/****************************************************************************** | ||
* Statistics | ||
******************************************************************************/ | ||
|
||
bool | ||
visit_mem (const mi_heap_t* heap, const mi_heap_area_t* heapinfo, void* block, | ||
size_t blocksize, void* arg) { | ||
int* count= (int*) arg; | ||
*count+= heapinfo->used; | ||
return true; | ||
} | ||
|
||
int | ||
mem_used () { | ||
mi_heap_t* heap = mi_heap_get_default (); | ||
int count= 0; | ||
mi_heap_visit_blocks (heap, false, visit_mem, &count); | ||
return count; | ||
} | ||
|
||
void | ||
mem_info () { | ||
cout << "\n---------------- memory statistics ----------------\n"; | ||
cout << "malloc overrided:" << mi_is_redirected () << "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.