mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-11 18:50:46 +00:00
update nedmalloc to r1116
git-svn-id: https://svn.eduke32.com/eduke32@1509 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
5ea5f4bc9b
commit
dcd7c3c9fe
4 changed files with 1275 additions and 942 deletions
|
@ -35,7 +35,9 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define REPLACE_SYSTEM_ALLOCATOR
|
#define USE_ALLOCATOR 1
|
||||||
|
#define REPLACE_SYSTEM_ALLOCATOR 1
|
||||||
|
#define USE_MAGIC_HEADERS 1
|
||||||
#include "nedmalloc.h"
|
#include "nedmalloc.h"
|
||||||
|
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
/* nedalloc, an alternative malloc implementation for multiple threads without
|
/* nedalloc, an alternative malloc implementation for multiple threads without
|
||||||
lock contention based on dlmalloc v2.8.3. (C) 2005 Niall Douglas
|
lock contention based on dlmalloc v2.8.3. (C) 2005-2009 Niall Douglas
|
||||||
|
|
||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
Boost Software License - Version 1.0 - August 17th, 2003
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ DEALINGS IN THE SOFTWARE.
|
||||||
#ifndef NEDMALLOC_H
|
#ifndef NEDMALLOC_H
|
||||||
#define NEDMALLOC_H
|
#define NEDMALLOC_H
|
||||||
|
|
||||||
#define THREADCACHEMAX 65536
|
|
||||||
#define THREADCACHEMAXFREESPACE (1024*1024*4)
|
|
||||||
|
|
||||||
/* See malloc.c.h for what each function does.
|
/* See malloc.c.h for what each function does.
|
||||||
|
|
||||||
|
@ -40,19 +38,34 @@ free etc. instead of nedmalloc, nedfree etc. You may or may not want this.
|
||||||
NO_NED_NAMESPACE prevents the functions from being defined in the nedalloc
|
NO_NED_NAMESPACE prevents the functions from being defined in the nedalloc
|
||||||
namespace when in C++ (uses the global namespace instead).
|
namespace when in C++ (uses the global namespace instead).
|
||||||
|
|
||||||
EXTSPEC can be defined to be __declspec(dllexport) or
|
NEDMALLOCEXTSPEC can be defined to be __declspec(dllexport) or
|
||||||
__attribute__ ((visibility("default"))) or whatever you like. It defaults
|
__attribute__ ((visibility("default"))) or whatever you like. It defaults
|
||||||
to extern.
|
to extern unless NEDMALLOC_DLL_EXPORTS is set as it would be when building
|
||||||
|
nedmalloc.dll.
|
||||||
|
|
||||||
USE_LOCKS can be 2 if you want to define your own MLOCK_T, INITIAL_LOCK,
|
USE_LOCKS can be 2 if you want to define your own MLOCK_T, INITIAL_LOCK,
|
||||||
ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER.
|
ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER.
|
||||||
|
|
||||||
|
USE_MAGIC_HEADERS causes nedalloc to allocate an extra three sizeof(size_t)
|
||||||
|
to each block. nedpfree() and nedprealloc() can then automagically know when
|
||||||
|
to free a system allocated block. Enabling this typically adds 20-50% to
|
||||||
|
application memory usage.
|
||||||
|
|
||||||
|
USE_ALLOCATOR can be one of these settings:
|
||||||
|
0: System allocator (nedmalloc now simply acts as a threadcache).
|
||||||
|
WARNING: Intended for DEBUG USE ONLY - not all functions work correctly.
|
||||||
|
1: dlmalloc
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h> /* for size_t */
|
#include <stddef.h> /* for size_t */
|
||||||
|
|
||||||
#ifndef EXTSPEC
|
#ifndef NEDMALLOCEXTSPEC
|
||||||
#define EXTSPEC extern
|
#ifdef NEDMALLOC_DLL_EXPORTS
|
||||||
|
#define NEDMALLOCEXTSPEC extern __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define NEDMALLOCEXTSPEC extern
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER>=1400
|
#if defined(_MSC_VER) && _MSC_VER>=1400
|
||||||
|
@ -65,32 +78,44 @@ ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER.
|
||||||
#define NEDMALLOCPTRATTR
|
#define NEDMALLOCPTRATTR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef USE_MAGIC_HEADERS
|
||||||
|
#define USE_MAGIC_HEADERS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef USE_ALLOCATOR
|
||||||
|
#define USE_ALLOCATOR 1 /* dlmalloc */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !USE_ALLOCATOR && !USE_MAGIC_HEADERS
|
||||||
|
#error If you are using the system allocator then you MUST use magic headers
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef REPLACE_SYSTEM_ALLOCATOR
|
#ifdef REPLACE_SYSTEM_ALLOCATOR
|
||||||
#define nedmalloc malloc
|
#if USE_ALLOCATOR==0
|
||||||
#define nedcalloc calloc
|
#error Cannot combine using the system allocator with replacing the system allocator
|
||||||
#define nedrealloc realloc
|
#endif
|
||||||
#define nedfree free
|
#ifndef WIN32 /* We have a dedidicated patcher for Windows */
|
||||||
#define nedmemalign memalign
|
#define nedmalloc malloc
|
||||||
#define nedmallinfo mallinfo
|
#define nedcalloc calloc
|
||||||
#define nedmallopt mallopt
|
#define nedrealloc realloc
|
||||||
#define nedmalloc_trim malloc_trim
|
#define nedfree free
|
||||||
#define nedmalloc_stats malloc_stats
|
#define nedmemalign memalign
|
||||||
#define nedmalloc_footprint malloc_footprint
|
#define nedmallinfo mallinfo
|
||||||
#define nedindependent_calloc independent_calloc
|
#define nedmallopt mallopt
|
||||||
#define nedindependent_comalloc independent_comalloc
|
#define nedmalloc_trim malloc_trim
|
||||||
#ifdef _MSC_VER
|
#define nedmalloc_stats malloc_stats
|
||||||
#define nedblksize _msize
|
#define nedmalloc_footprint malloc_footprint
|
||||||
|
#define nedindependent_calloc independent_calloc
|
||||||
|
#define nedindependent_comalloc independent_comalloc
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define nedblksize _msize
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
|
||||||
#ifndef UNREFERENCED_PARAMETER
|
|
||||||
#define UNREFERENCED_PARAMETER(x) x=x
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NO_MALLINFO
|
#ifndef NO_MALLINFO
|
||||||
#define NO_MALLINFO 0
|
#define NO_MALLINFO 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !NO_MALLINFO
|
#if !NO_MALLINFO
|
||||||
|
@ -117,33 +142,36 @@ extern "C" {
|
||||||
/* These are the global functions */
|
/* These are the global functions */
|
||||||
|
|
||||||
/* Gets the usable size of an allocated block. Note this will always be bigger than what was
|
/* Gets the usable size of an allocated block. Note this will always be bigger than what was
|
||||||
asked for due to rounding etc.
|
asked for due to rounding etc. Tries to return zero if this is not a nedmalloc block (though
|
||||||
|
one could see a segfault up to 6.25% of the time). On Win32 SEH is used to guarantee that a
|
||||||
|
segfault never happens.
|
||||||
*/
|
*/
|
||||||
EXTSPEC size_t nedblksize(void *mem) THROWSPEC;
|
NEDMALLOCEXTSPEC size_t nedblksize(void *mem) THROWSPEC;
|
||||||
|
|
||||||
EXTSPEC void nedsetvalue(void *v) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedsetvalue(void *v) THROWSPEC;
|
||||||
|
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC;
|
||||||
EXTSPEC void nedfree(void *mem) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedfree(void *mem) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC;
|
||||||
#if !NO_MALLINFO
|
#if !NO_MALLINFO
|
||||||
EXTSPEC struct mallinfo nedmallinfo(void) THROWSPEC;
|
NEDMALLOCEXTSPEC struct mallinfo nedmallinfo(void) THROWSPEC;
|
||||||
#endif
|
#endif
|
||||||
EXTSPEC int nedmallopt(int parno, int value) THROWSPEC;
|
NEDMALLOCEXTSPEC int nedmallopt(int parno, int value) THROWSPEC;
|
||||||
EXTSPEC int nedmalloc_trim(size_t pad) THROWSPEC;
|
NEDMALLOCEXTSPEC void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC;
|
||||||
EXTSPEC void nedmalloc_stats(void) THROWSPEC;
|
NEDMALLOCEXTSPEC int nedmalloc_trim(size_t pad) THROWSPEC;
|
||||||
EXTSPEC size_t nedmalloc_footprint(void) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedmalloc_stats(void) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
NEDMALLOCEXTSPEC size_t nedmalloc_footprint(void) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
||||||
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
||||||
|
|
||||||
/* Destroys the system memory pool used by the functions above.
|
/* Destroys the system memory pool used by the functions above.
|
||||||
Useful for when you have nedmalloc in a DLL you're about to unload.
|
Useful for when you have nedmalloc in a DLL you're about to unload.
|
||||||
If you call ANY nedmalloc functions after calling this you will
|
If you call ANY nedmalloc functions after calling this you will
|
||||||
get a fatal exception!
|
get a fatal exception!
|
||||||
*/
|
*/
|
||||||
EXTSPEC void neddestroysyspool(void) THROWSPEC;
|
NEDMALLOCEXTSPEC void neddestroysyspool() THROWSPEC;
|
||||||
|
|
||||||
/* These are the pool functions */
|
/* These are the pool functions */
|
||||||
struct nedpool_t;
|
struct nedpool_t;
|
||||||
|
@ -156,52 +184,50 @@ will *normally* be accessing the pool concurrently. Setting this to zero means i
|
||||||
extends on demand, but be careful of this as it can rapidly consume system resources
|
extends on demand, but be careful of this as it can rapidly consume system resources
|
||||||
where bursts of concurrent threads use a pool at once.
|
where bursts of concurrent threads use a pool at once.
|
||||||
*/
|
*/
|
||||||
EXTSPEC NEDMALLOCPTRATTR nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC;
|
||||||
|
|
||||||
/* Destroys a memory pool previously created by nedcreatepool().
|
/* Destroys a memory pool previously created by nedcreatepool().
|
||||||
*/
|
*/
|
||||||
EXTSPEC void neddestroypool(nedpool *p) THROWSPEC;
|
NEDMALLOCEXTSPEC void neddestroypool(nedpool *p) THROWSPEC;
|
||||||
|
|
||||||
/* Sets a value to be associated with a pool. You can retrieve this value by passing
|
/* Sets a value to be associated with a pool. You can retrieve this value by passing
|
||||||
any memory block allocated from that pool.
|
any memory block allocated from that pool.
|
||||||
*/
|
*/
|
||||||
EXTSPEC void nedpsetvalue(nedpool *p, void *v) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedpsetvalue(nedpool *p, void *v) THROWSPEC;
|
||||||
/* Gets a previously set value using nedpsetvalue() or zero if memory is unknown.
|
/* Gets a previously set value using nedpsetvalue() or zero if memory is unknown.
|
||||||
Optionally can also retrieve pool.
|
Optionally can also retrieve pool.
|
||||||
*/
|
*/
|
||||||
EXTSPEC void *nedgetvalue(nedpool **p, void *mem) THROWSPEC;
|
NEDMALLOCEXTSPEC void *nedgetvalue(nedpool **p, void *mem) THROWSPEC;
|
||||||
|
|
||||||
/* Trims the thread cache for the calling thread, returning any existing cache
|
/* Trims the thread cache for the calling thread, returning any existing cache
|
||||||
data to the central pool. Remember to ALWAYS call with zero if you used the
|
data to the central pool. Remember to ALWAYS call with zero if you used the
|
||||||
system pool. Setting disable to non-zero replicates neddisablethreadcache().
|
system pool. Setting disable to non-zero replicates neddisablethreadcache().
|
||||||
*/
|
*/
|
||||||
EXTSPEC void nedtrimthreadcache(nedpool *p, int disable) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedtrimthreadcache(nedpool *p, int disable) THROWSPEC;
|
||||||
|
|
||||||
/* Disables the thread cache for the calling thread, returning any existing cache
|
/* Disables the thread cache for the calling thread, returning any existing cache
|
||||||
data to the central pool. Remember to ALWAYS call with zero if you used the
|
data to the central pool. Remember to ALWAYS call with zero if you used the
|
||||||
system pool.
|
system pool.
|
||||||
*/
|
*/
|
||||||
EXTSPEC void neddisablethreadcache(nedpool *p) THROWSPEC;
|
NEDMALLOCEXTSPEC void neddisablethreadcache(nedpool *p) THROWSPEC;
|
||||||
|
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedpmalloc(nedpool *p, size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpmalloc(nedpool *p, size_t size) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC;
|
||||||
EXTSPEC void nedpfree(nedpool *p, void *mem) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedpfree(nedpool *p, void *mem) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) THROWSPEC;
|
||||||
#if !NO_MALLINFO
|
#if !NO_MALLINFO
|
||||||
EXTSPEC struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC;
|
NEDMALLOCEXTSPEC struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC;
|
||||||
#endif
|
#endif
|
||||||
EXTSPEC int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC;
|
NEDMALLOCEXTSPEC int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC;
|
||||||
EXTSPEC int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC;
|
NEDMALLOCEXTSPEC int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC;
|
||||||
EXTSPEC void nedpmalloc_stats(nedpool *p) THROWSPEC;
|
NEDMALLOCEXTSPEC void nedpmalloc_stats(nedpool *p) THROWSPEC;
|
||||||
EXTSPEC size_t nedpmalloc_footprint(nedpool *p) THROWSPEC;
|
NEDMALLOCEXTSPEC size_t nedpmalloc_footprint(nedpool *p) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
||||||
EXTSPEC NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef EXTSPEC
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue