1
0
mirror of https://github.com/ErnyTech/neomimalloc synced 2024-09-27 16:56:53 +02:00

Compare commits

...

10 Commits

Author SHA1 Message Date
Ernesto Castellotti
330af5b9ca
libmimalloc-sys: Updated to v1.0.6 2019-08-17 10:39:46 +02:00
Ernesto Castellotti
3e35f5593f
c bindings: Update header to v1.0.6 2019-08-17 10:38:29 +02:00
Ernesto Castellotti
a3ef3650c6
libmimalloc-sys: Updated to v1.0.5 2019-07-17 16:17:15 +02:00
Ernesto Castellotti
09ae5e9879
c bindings: Update header to v1.0.5 2019-07-17 16:16:36 +02:00
Ernesto Castellotti
a455e21c9b Remove old submodule path 2019-07-11 17:37:19 +02:00
Ernesto Castellotti
534550839c c bindings: Update header to v1.0.3 2019-07-11 17:29:12 +02:00
Ernesto Castellotti
35e3ed8b1a dub.json: switch to separed C dependency design 2019-07-11 17:28:55 +02:00
Ernesto Castellotti
f3efa1f672
dub: clean the temporary folder instead of just the build folder 2019-07-05 15:06:11 +02:00
Ernesto Castellotti
b9584e861f Fix build regression
Now mimalloc symbols are inside neomimalloc library
2019-07-05 01:33:49 +02:00
Ernesto Castellotti
b8b9ab9a55
Constify the parameters of some functions that can become it 2019-07-05 00:35:32 +02:00
5 changed files with 185 additions and 112 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "source/mimalloc"]
path = source/mimalloc
url = https://github.com/microsoft/mimalloc

View File

@ -6,49 +6,8 @@
],
"copyright": "Copyright © 2019, Ernesto Castellotti <erny.castell@gmail.com>",
"license": "MPL-2.0",
"configurations": [
{
"name" : "standard",
"preBuildCommands-posix" : [
"cd $PACKAGE_DIR && git clone --recursive https://github.com/ErnyTech/neomimalloc || true",
"cd $PACKAGE_DIR/neomimalloc/source/mimalloc && rm -rf build && mkdir build && cd build && cmake -DMI_OVERRIDE=OFF .. && make"
],
"sourceFiles": [
"$PACKAGE_DIR/neomimalloc/source/mimalloc/build/libmimalloc.a"
]
},
{
"name" : "secure",
"preBuildCommands-posix" : [
"cd $PACKAGE_DIR && git clone --recursive https://github.com/ErnyTech/neomimalloc || true",
"cd $PACKAGE_DIR/neomimalloc/source/mimalloc && rm -rf build && mkdir build && cd build && cmake -DMI_OVERRIDE=OFF -DMI_SECURE=ON .. && make"
],
"sourceFiles": [
"$PACKAGE_DIR/neomimalloc/source/mimalloc/build/libmimalloc-secure.a"
]
},
{
"name" : "override-malloc",
"preBuildCommands-posix" : [
"cd $PACKAGE_DIR && git clone --recursive https://github.com/ErnyTech/neomimalloc || true",
"cd $PACKAGE_DIR/neomimalloc/source/mimalloc && rm -rf build && mkdir build && cd build && cmake -DMI_OVERRIDE=ON .. && make"
],
"sourceFiles": [
"$PACKAGE_DIR/neomimalloc/source/mimalloc/build/libmimalloc.a"
]
},
{
"name" : "override-malloc-secure",
"preBuildCommands-posix" : [
"cd $PACKAGE_DIR && git clone --recursive https://github.com/ErnyTech/neomimalloc || true",
"cd $PACKAGE_DIR/neomimalloc/source/mimalloc && rm -rf build && mkdir build && cd build && cmake -DMI_OVERRIDE=ON -DMI_SECURE=ON .. && make"
],
"sourceFiles": [
"$PACKAGE_DIR/neomimalloc/source/mimalloc/build/libmimalloc-secure.a"
]
},
{
"name" : "manual-link"
}
]
"systemDependencies" : "libc and thread support (e.g. glibc and pthread), to build also needs for cmake and a C toolchain",
"dependencies": {
"libmimalloc-sys": "==1.0.6"
}
}

@ -1 +0,0 @@
Subproject commit 1125271c2756ee1db1303918816fea35e08b3405

View File

@ -68,20 +68,21 @@ extern(C) {
alias mi_block_visit_fun = bool function(const(mi_heap_t)* heap,
const(mi_heap_area_t)* area,
void* block, size_t block_size,
void* arg);
const(void)* arg);
/**
* Runtime options.
*/
enum mi_option_t {
mi_option_page_reset = 0, /** Reset page memory when it becomes free. */
mi_option_cache_reset = 1, /** Reset segment memory when a segment is cached. */
mi_option_pool_commit = 2, /** Commit segments in large pools. */
mi_option_secure = 3,
mi_option_show_stats = 4, /** Print statistics to stderr when the program is done. */
mi_option_show_errors = 5, /** Print error messages to stderr. */
mi_option_verbose = 6, /** Print verbose messages to stderr. */
_mi_option_last = 7
enum mi_option_t {
mi_option_show_stats = 0, /** Print statistics to stderr when the program is done. */
mi_option_show_errors = 1, /** Print error messages to stderr. */
mi_option_verbose = 2, /** Print verbose messages to stderr. */
mi_option_secure = 3, /** Experimental*/
mi_option_pool_commit = 4, /** Experimental: Commit segments in large pools. */
mi_option_large_os_pages = 5, /** Experimental: Use large os pages */
mi_option_page_reset = 6, /** Experimental: Reset page memory when it becomes free. */
mi_option_cache_reset = 7, /** Experimental: Reset segment memory when a segment is cached. */
_mi_option_last = 8
}
/**
@ -174,32 +175,6 @@ extern(C) {
* Pointer to newly allocated zero initialized memory, or NULL if out of memory.
*/
@nogc pure @system nothrow void* mi_zalloc(size_t size);
/**
* Reallocate memory to newsize bytes, with extra memory initialized to zero.
*
* Params:
* p = Pointer to a previously allocated block (or NULL).
* newsize = The new required size in bytes.
*
* Returns:
* A pointer to a re-allocated block of newsize bytes, or NULL if out of memory.
*
* If the newsize is larger than the original allocated size of p, the extra bytes are initialized to zero.
*/
@nogc pure @system nothrow void* mi_rezalloc(void* p, size_t newsize);
/**
* Re-allocate memory to newsize bytes.
*
* Params:
* p = pointer to previously allocated memory (or NULL).
* newsize = the new required size in bytes.
*
* Returns:
* pointer to the re-allocated memory of newsize bytes, or NULL if out of memory. If NULL is returned, the pointer p is not freed. Otherwise the original pointer is either freed or returned as the reallocated result (in case it fits in-place with the new size). If the pointer p is NULL, it behaves as mi_malloc(newsize). If newsize is larger than the original size allocated for p, the bytes after size are uninitialized.
*/
@nogc pure @system nothrow void* mi_recalloc(void* p, size_t count, size_t size);
/**
* Try to re-allocate memory to newsize bytes in place.
@ -299,7 +274,7 @@ extern(C) {
*
* The returned size can be used to call mi_expand successfully. The returned size is always at least equal to the allocated size of p, and, in the current design, should be less than 16.7% more.
*/
@nogc pure @system nothrow size_t mi_usable_size(void* p);
@nogc pure @system nothrow size_t mi_usable_size(const(void)* p);
/**
* Return the used allocation size.
@ -339,6 +314,12 @@ extern(C) {
*/
@nogc @system nothrow void mi_stats_reset();
/**
* Get mimalloc version
*/
@nogc pure @system nothrow int mi_version();
/**
* Initialize mimalloc on a process
*/
@ -376,7 +357,7 @@ extern(C) {
*
* Some runtime systems use deferred free-ing, for example when using reference counting to limit the worst case free time. Such systems can register (re-entrant) deferred free function to free more memory on demand. When the force parameter is true all possible memory should be freed. The per-thread heartbeat parameter is monotonically increasing and guaranteed to be deterministic if the program allocates deterministically. The deferred_free function is guaranteed to be called deterministically after some number of allocations (regardless of freeing or available free memory). At most one deferred_free function can be active.
*/
@nogc @system nothrow void mi_register_deferred_free(mi_deferred_free_fun deferred_free);
@nogc @system nothrow void mi_register_deferred_free(const(mi_deferred_free_fun) deferred_free);
/**
* Allocate size bytes aligned by alignment.
@ -436,26 +417,6 @@ extern(C) {
* Re-allocate memory to newsize bytes aligned by alignment at a specified offset.
*/
@nogc pure @system nothrow void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
/**
* Reallocate memory to newsize bytes, with extra memory initialized to zero aligned by alignment.
*/
@nogc pure @system nothrow void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment);
/**
* Reallocate memory to newsize bytes, with extra memory initialized to zero aligned by alignment at a specified offset.
*/
@nogc pure @system nothrow void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset);
/**
* Re-allocate memory to newsize bytes aligned by alignment.
*/
@nogc pure @system nothrow void* mi_recalloc_aligned(void* p, size_t count, size_t size, size_t alignment);
/**
* Re-allocate memory to newsize bytes aligned by alignment at a specified offset.
*/
@nogc pure @system nothrow void* mi_recalloc_aligned_at(void* p, size_t count, size_t size, size_t alignment, size_t offset);
/**
* Create a new heap that can be used for allocation.
@ -535,6 +496,21 @@ extern(C) {
* Allocate a small object in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_malloc_small(mi_heap_t* heap, size_t size);
/**
* Re-allocate memory to newsize bytes in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize);
/**
* Re-allocate memory to count elements of size bytes in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size);
/**
* Re-allocate memory to newsize bytes in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_reallocf(mi_heap_t* heap, void* p, size_t newsize);
/**
* Duplicate a string in a specific heap.
@ -550,6 +526,46 @@ extern(C) {
* Resolve a file path name using a specific heap to allocate the result.
*/
@nogc pure @system nothrow char* mi_heap_realpath(mi_heap_t* heap, const(char)* fname, char* resolved_name);
/**
* Allocate size bytes aligned by alignment in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
/**
* Allocate size bytes aligned by alignment at a specified offset in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
/**
* Allocate zero-initialized size bytes aligned by alignment in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment);
/**
* Allocate zero-initialized size bytes aligned by alignment at a specified offset in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_zalloc_aligned_at (mi_heap_t* heap, size_t size, size_t alignment, size_t offset);
/**
* Allocate zero-initialized count elements of size bytes aligned by alignment in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment);
/**
* Allocate zero-initialized count elements of size bytes aligned by alignment at a specified offset in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset);
/**
* Re-allocate memory to newsize bytes aligned by alignment in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment);
/**
* Re-allocate memory to newsize bytes aligned by alignment at a specified offset in a specific heap.
*/
@nogc pure @system nothrow void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset);
/**
* Does a heap contain a pointer to a previously allocated block?
@ -602,8 +618,13 @@ extern(C) {
* Returns:
* true if all areas and blocks were visited.
*/
@nogc pure @system nothrow bool mi_heap_visit_blocks(const(mi_heap_t)* heap, bool visit_all_blocks, mi_block_visit_fun visitor, void* arg);
@nogc pure @system nothrow bool mi_heap_visit_blocks(const(mi_heap_t)* heap, bool visit_all_blocks, mi_block_visit_fun visitor, const(void)* arg);
/**
* Inspect the heap at runtime.
*/
@nogc pure @system nothrow bool mi_is_in_heap_region(const(void)* p);
/**
* Set runtime behavior.
*/
@ -633,4 +654,101 @@ extern(C) {
* Set runtime behavior.
*/
@nogc @system nothrow void mi_option_set_default(mi_option_t option, c_long value);
}
/**
* Re-allocate memory to newsize bytes.
*
* Params:
* p = pointer to previously allocated memory (or NULL).
* newsize = the new required size in bytes.
*
* Returns:
* pointer to the re-allocated memory of newsize bytes, or NULL if out of memory. If NULL is returned, the pointer p is not freed. Otherwise the original pointer is either freed or returned as the reallocated result (in case it fits in-place with the new size). If the pointer p is NULL, it behaves as mi_malloc(newsize). If newsize is larger than the original size allocated for p, the bytes after size are uninitialized.
*/
@nogc pure @system nothrow void* mi_recalloc(void* p, size_t count, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow size_t mi_malloc_size(const(void)* p);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow size_t mi_malloc_usable_size(const(void)* p);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow size_t mi_cfree(void* p);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow int mi_posix_memalign(void** p, size_t alignment, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow int mi__posix_memalign(void** p, size_t alignment, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_memalign(size_t alignment, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_valloc(size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_pvalloc(size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_aligned_alloc(size_t alignment, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_reallocarray(void* p, size_t count, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void mi_free_size(void* p, size_t size);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void mi_free_size_aligned(void* p, size_t size, size_t alignment);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void mi_free_aligned(void* p, size_t alignment);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system void* mi_new(size_t n);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system void* mi_new_aligned(size_t n, size_t alignment);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_new_nothrow(size_t n);
/**
* mi prefixed implementations of various posix, unix, and C++ allocation functions
*/
@nogc pure @system nothrow void* mi_new_aligned_nothrow(size_t n, size_t alignment);
}

View File

@ -202,7 +202,7 @@ struct Mimallocator {
}
auto sizeOfP = mi_usable_size(p);
result = p[0 .. sizeOfP];
result = (cast(void*) p)[0 .. sizeOfP];
return Ternary.yes;
}
@ -233,6 +233,6 @@ struct Mimallocator {
return false;
}
return mi_check_owned(b.ptr);
return mi_check_owned(p);
}
}
}