Packages
rocksdb
2.6.1
3.1.1
3.1.0
3.0.0
2.6.2
2.6.1
retired
2.6.0
retired
2.5.0
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
0.26.2
0.26.1
0.26.0
0.25.0
0.24.0
0.23.3
0.23.2
0.23.1
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
RocksDB for Erlang
Retired package: Release invalid - Build broken, use 2.6.2
Current section
Files
Jump to
Current section
Files
deps/CRoaring/src/memory.c
#include <stdlib.h>
#include <roaring/memory.h>
// without the following, we get lots of warnings about posix_memalign
#ifndef __cplusplus
extern int posix_memalign(void** __memptr, size_t __alignment, size_t __size);
#endif //__cplusplus // C++ does not have a well defined signature
// portable version of posix_memalign
static void* roaring_bitmap_aligned_malloc(size_t alignment, size_t size) {
void* p;
#ifdef _MSC_VER
p = _aligned_malloc(size, alignment);
#elif defined(__MINGW32__) || defined(__MINGW64__)
p = __mingw_aligned_malloc(size, alignment);
#else
// somehow, if this is used before including "x86intrin.h", it creates an
// implicit defined warning.
if (posix_memalign(&p, alignment, size) != 0) return NULL;
#endif
return p;
}
static void roaring_bitmap_aligned_free(void* memblock) {
#ifdef _MSC_VER
_aligned_free(memblock);
#elif defined(__MINGW32__) || defined(__MINGW64__)
__mingw_aligned_free(memblock);
#else
free(memblock);
#endif
}
static roaring_memory_t global_memory_hook = {
.malloc = malloc,
.realloc = realloc,
.calloc = calloc,
.free = free,
.aligned_malloc = roaring_bitmap_aligned_malloc,
.aligned_free = roaring_bitmap_aligned_free,
};
void roaring_init_memory_hook(roaring_memory_t memory_hook) {
global_memory_hook = memory_hook;
}
void* roaring_malloc(size_t n) { return global_memory_hook.malloc(n); }
void* roaring_realloc(void* p, size_t new_sz) {
return global_memory_hook.realloc(p, new_sz);
}
void* roaring_calloc(size_t n_elements, size_t element_size) {
return global_memory_hook.calloc(n_elements, element_size);
}
void roaring_free(void* p) { global_memory_hook.free(p); }
void* roaring_aligned_malloc(size_t alignment, size_t size) {
return global_memory_hook.aligned_malloc(alignment, size);
}
void roaring_aligned_free(void* p) { global_memory_hook.aligned_free(p); }