Drop nedmalloc which is apparently not used anymore
This commit is contained in:
parent
292132ef6b
commit
f63bf12193
14 changed files with 2 additions and 8003 deletions
1
drivers/SCsub
vendored
1
drivers/SCsub
vendored
|
@ -40,7 +40,6 @@ if (env["builtin_zlib"]=="yes"):
|
||||||
SConscript("builtin_zlib/SCsub");
|
SConscript("builtin_zlib/SCsub");
|
||||||
|
|
||||||
SConscript("rtaudio/SCsub");
|
SConscript("rtaudio/SCsub");
|
||||||
SConscript("nedmalloc/SCsub");
|
|
||||||
SConscript("nrex/SCsub");
|
SConscript("nrex/SCsub");
|
||||||
SConscript("chibi/SCsub");
|
SConscript("chibi/SCsub");
|
||||||
if (env["vorbis"]=="yes" or env["theoralib"]=="yes" or env["opus"]=="yes"):
|
if (env["vorbis"]=="yes" or env["theoralib"]=="yes" or env["opus"]=="yes"):
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute,
|
|
||||||
execute, and transmit the Software, and to prepare derivative works of the
|
|
||||||
Software, and to permit third-parties to whom the Software is furnished to
|
|
||||||
do so, all subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer,
|
|
||||||
must be included in all copies of the Software, in whole or in part, and
|
|
||||||
all derivative works of the Software, unless such copies or derivative
|
|
||||||
works are solely in the form of machine-executable object code generated by
|
|
||||||
a source language processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
||||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
|
@ -1,136 +0,0 @@
|
||||||
nedalloc v1.05 15th June 2008:
|
|
||||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
||||||
|
|
||||||
by Niall Douglas (http://www.nedprod.com/programs/portable/nedmalloc/)
|
|
||||||
|
|
||||||
Enclosed is nedalloc, an alternative malloc implementation for multiple
|
|
||||||
threads without lock contention based on dlmalloc v2.8.4. It is more
|
|
||||||
or less a newer implementation of ptmalloc2, the standard allocator in
|
|
||||||
Linux (which is based on dlmalloc v2.7.0) but also contains a per-thread
|
|
||||||
cache for maximum CPU scalability.
|
|
||||||
|
|
||||||
It is licensed under the Boost Software License which basically means
|
|
||||||
you can do anything you like with it. This does not apply to the malloc.c.h
|
|
||||||
file which remains copyright to others.
|
|
||||||
|
|
||||||
It has been tested on win32 (x86), win64 (x64), Linux (x64), FreeBSD (x64)
|
|
||||||
and Apple MacOS X (x86). It works very well on all of these and is very
|
|
||||||
significantly faster than the system allocator on all of these platforms.
|
|
||||||
|
|
||||||
By literally dropping in this allocator as a replacement for your system
|
|
||||||
allocator, you can see real world improvements of up to three times in normal
|
|
||||||
code!
|
|
||||||
|
|
||||||
To use:
|
|
||||||
-=-=-=-
|
|
||||||
Drop in nedmalloc.h, nedmalloc.c and malloc.c.h into your project.
|
|
||||||
Configure using the instructions in nedmalloc.h. Run and enjoy.
|
|
||||||
|
|
||||||
To test, compile test.c. It will run a comparison between your system
|
|
||||||
allocator and nedalloc and tell you how much faster nedalloc is. It also
|
|
||||||
serves as an example of usage.
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
-=-=-=
|
|
||||||
If you want the very latest version of this allocator, get it from the
|
|
||||||
TnFOX SVN repository at svn://svn.berlios.de/viewcvs/tnfox/trunk/src/nedmalloc
|
|
||||||
|
|
||||||
Because of how nedalloc allocates an mspace per thread, it can cause
|
|
||||||
severe bloating of memory usage under certain allocation patterns.
|
|
||||||
You can substantially reduce this wastage by setting MAXTHREADSINPOOL
|
|
||||||
or the threads parameter to nedcreatepool() to a fraction of the number of
|
|
||||||
threads which would normally be in a pool at once. This will reduce
|
|
||||||
bloating at the cost of an increase in lock contention. If allocated size
|
|
||||||
is less than THREADCACHEMAX, locking is avoided 90-99% of the time and
|
|
||||||
if most of your allocations are below this value, you can safely set
|
|
||||||
MAXTHREADSINPOOL to one.
|
|
||||||
|
|
||||||
You will suffer memory leakage unless you call neddisablethreadcache()
|
|
||||||
per pool for every thread which exits. This is because nedalloc cannot
|
|
||||||
portably know when a thread exits and thus when its thread cache can
|
|
||||||
be returned for use by other code. Don't forget pool zero, the system pool.
|
|
||||||
|
|
||||||
For C++ type allocation patterns (where the same sizes of memory are
|
|
||||||
regularly allocated and deallocated as objects are created and destroyed),
|
|
||||||
the threadcache always benefits performance. If however your allocation
|
|
||||||
patterns are different, searching the threadcache may significantly slow
|
|
||||||
down your code - as a rule of thumb, if cache utilisation is below 80%
|
|
||||||
(see the source for neddisablethreadcache() for how to enable debug
|
|
||||||
printing in release mode) then you should disable the thread cache for
|
|
||||||
that thread. You can compile out the threadcache code by setting
|
|
||||||
THREADCACHEMAX to zero.
|
|
||||||
|
|
||||||
Speed comparisons:
|
|
||||||
-=-=-=-=-=-=-=-=-=
|
|
||||||
See Benchmarks.xls for details.
|
|
||||||
|
|
||||||
The enclosed test.c can do two things: it can be a torture test or a speed
|
|
||||||
test. The speed test is designed to be a representative synthetic
|
|
||||||
memory allocator test. It works by randomly mixing allocations with frees
|
|
||||||
with half of the allocation sizes being a two power multiple less than
|
|
||||||
512 bytes (to mimic C++ stack instantiated objects) and the other half
|
|
||||||
being a simple random value less than 16Kb.
|
|
||||||
|
|
||||||
The real world code results are from Tn's TestIO benchmark. This is a
|
|
||||||
heavily multithreaded and memory intensive benchmark with a lot of branching
|
|
||||||
and other stuff modern processors don't like so much. As you'll note, the
|
|
||||||
test doesn't show the benefits of the threadcache mostly due to the saturation
|
|
||||||
of the memory bus being the limiting factor.
|
|
||||||
|
|
||||||
ChangeLog:
|
|
||||||
-=-=-=-=-=
|
|
||||||
v1.05 15th June 2008:
|
|
||||||
* { 1042 } Added error check for TLSSET() and TLSFREE() macros. Thanks to
|
|
||||||
Markus Elfring for reporting this.
|
|
||||||
* { 1043 } Fixed a segfault when freeing memory allocated using
|
|
||||||
nedindependent_comalloc(). Thanks to Pavel Vozenilek for reporting this.
|
|
||||||
|
|
||||||
v1.04 14th July 2007:
|
|
||||||
* Fixed a bug with the new optimised implementation that failed to lock
|
|
||||||
on a realloc under certain conditions.
|
|
||||||
* Fixed lack of thread synchronisation in InitPool() causing pool corruption
|
|
||||||
* Fixed a memory leak of thread cache contents on disabling. Thanks to Earl
|
|
||||||
Chew for reporting this.
|
|
||||||
* Added a sanity check for freed blocks being valid.
|
|
||||||
* Reworked test.c into being a torture test.
|
|
||||||
* Fixed GCC assembler optimisation misspecification
|
|
||||||
|
|
||||||
v1.04alpha_svn915 7th October 2006:
|
|
||||||
* Fixed failure to unlock thread cache list if allocating a new list failed.
|
|
||||||
Thanks to Dmitry Chichkov for reporting this. Futher thanks to Aleksey Sanin.
|
|
||||||
* Fixed realloc(0, <size>) segfaulting. Thanks to Dmitry Chichkov for
|
|
||||||
reporting this.
|
|
||||||
* Made config defines #ifndef so they can be overriden by the build system.
|
|
||||||
Thanks to Aleksey Sanin for suggesting this.
|
|
||||||
* Fixed deadlock in nedprealloc() due to unnecessary locking of preferred
|
|
||||||
thread mspace when mspace_realloc() always uses the original block's mspace
|
|
||||||
anyway. Thanks to Aleksey Sanin for reporting this.
|
|
||||||
* Made some speed improvements by hacking mspace_malloc() to no longer lock
|
|
||||||
its mspace, thus allowing the recursive mutex implementation to be removed
|
|
||||||
with an associated speed increase. Thanks to Aleksey Sanin for suggesting this.
|
|
||||||
* Fixed a bug where allocating mspaces overran its max limit. Thanks to
|
|
||||||
Aleksey Sanin for reporting this.
|
|
||||||
|
|
||||||
v1.03 10th July 2006:
|
|
||||||
* Fixed memory corruption bug in threadcache code which only appeared with >4
|
|
||||||
threads and in heavy use of the threadcache.
|
|
||||||
|
|
||||||
v1.02 15th May 2006:
|
|
||||||
* Integrated dlmalloc v2.8.4, fixing the win32 memory release problem and
|
|
||||||
improving performance still further. Speed is now up to twice the speed of v1.01
|
|
||||||
(average is 67% faster).
|
|
||||||
* Fixed win32 critical section implementation. Thanks to Pavel Kuznetsov
|
|
||||||
for reporting this.
|
|
||||||
* Wasn't locking mspace if all mspaces were locked. Thanks to Pavel Kuznetsov
|
|
||||||
for reporting this.
|
|
||||||
* Added Apple Mac OS X support.
|
|
||||||
|
|
||||||
v1.01 24th February 2006:
|
|
||||||
* Fixed multiprocessor scaling problems by removing sources of cache sloshing
|
|
||||||
* Earl Chew <earl_chew <at> agilent <dot> com> sent patches for the following:
|
|
||||||
1. size2binidx() wasn't working for default code path (non x86)
|
|
||||||
2. Fixed failure to release mspace lock under certain circumstances which
|
|
||||||
caused a deadlock
|
|
||||||
|
|
||||||
v1.00 1st January 2006:
|
|
||||||
* First release
|
|
|
@ -1,4 +0,0 @@
|
||||||
Import('env')
|
|
||||||
Export('env');
|
|
||||||
|
|
||||||
env.add_source_files(env.drivers_sources,"*.cpp")
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,163 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* memory_pool_static_nedmalloc.cpp */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* http://www.godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
#ifdef NEDMALLOC_ENABLED
|
|
||||||
|
|
||||||
//
|
|
||||||
// C++ Implementation: memory_static_malloc
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Author: Juan Linietsky <red@lunatea>, (C) 2006
|
|
||||||
//
|
|
||||||
// Copyright: See COPYING file that comes with this distribution
|
|
||||||
//
|
|
||||||
//
|
|
||||||
#include "memory_pool_static_nedmalloc.h"
|
|
||||||
#include "error_macros.h"
|
|
||||||
#include "os/memory.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "os/copymem.h"
|
|
||||||
#include "os/os.h"
|
|
||||||
|
|
||||||
#include "nedmalloc.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NOTE NOTE NOTE NOTE
|
|
||||||
* in debug mode, this appends the memory size before the allocated, returned pointer
|
|
||||||
* so BE CAREFUL!
|
|
||||||
*/
|
|
||||||
|
|
||||||
void* MemoryPoolStaticNedMalloc::alloc(size_t p_bytes,const char *p_description) {
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(p_bytes==0,0);
|
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
void *mem=nedalloc::nedmalloc(p_bytes);
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!mem,0); //out of memory, or unreasonable request
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void* MemoryPoolStaticNedMalloc::realloc(void *p_memory,size_t p_bytes) {
|
|
||||||
|
|
||||||
if (p_memory==NULL) {
|
|
||||||
|
|
||||||
return alloc( p_bytes );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_bytes<=0) {
|
|
||||||
|
|
||||||
this->free(p_memory);
|
|
||||||
ERR_FAIL_COND_V( p_bytes < 0 , NULL );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
return nedalloc::nedrealloc( p_memory, p_bytes );
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryPoolStaticNedMalloc::free(void *p_ptr) {
|
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
ERR_FAIL_COND(p_ptr==0);
|
|
||||||
|
|
||||||
nedalloc::nedfree(p_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t MemoryPoolStaticNedMalloc::get_available_mem() const {
|
|
||||||
|
|
||||||
return 0xffffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MemoryPoolStaticNedMalloc::get_total_usage() {
|
|
||||||
|
|
||||||
return nedalloc::nedmalloc_footprint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Most likely available only if memory debugger was compiled in */
|
|
||||||
int MemoryPoolStaticNedMalloc::get_alloc_count() {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
void * MemoryPoolStaticNedMalloc::get_alloc_ptr(int p_alloc_idx) {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
const char* MemoryPoolStaticNedMalloc::get_alloc_description(int p_alloc_idx) {
|
|
||||||
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
size_t MemoryPoolStaticNedMalloc::get_alloc_size(int p_alloc_idx) {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MemoryPoolStaticNedMalloc::debug_print_all_memory() {
|
|
||||||
|
|
||||||
nedalloc::nedmalloc_stats();
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryPoolStaticNedMalloc::MemoryPoolStaticNedMalloc() {
|
|
||||||
|
|
||||||
mutex=NULL;
|
|
||||||
#ifndef NO_THREADS
|
|
||||||
|
|
||||||
mutex=Mutex::create(); // at this point, this should work
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MemoryPoolStaticNedMalloc::~MemoryPoolStaticNedMalloc() {
|
|
||||||
|
|
||||||
Mutex *old_mutex=mutex;
|
|
||||||
mutex=NULL;
|
|
||||||
if (old_mutex)
|
|
||||||
memdelete(old_mutex);
|
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
|
|
||||||
if (OS::get_singleton()->is_stdout_verbose())
|
|
||||||
nedalloc::nedmalloc_stats();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* memory_pool_static_nedmalloc.h */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* http://www.godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
#ifdef NEDMALLOC_ENABLED
|
|
||||||
|
|
||||||
//
|
|
||||||
// C++ Interface: memory_static_malloc
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Author: Juan Linietsky <red@lunatea>, (C) 2006
|
|
||||||
//
|
|
||||||
// Copyright: See COPYING file that comes with this distribution
|
|
||||||
//
|
|
||||||
//
|
|
||||||
#ifndef MEMORY_POOL_STATIC_NEDMALLOC_H
|
|
||||||
#define MEMORY_POOL_STATIC_NEDMALLOC_H
|
|
||||||
|
|
||||||
#include "os/memory_pool_static.h"
|
|
||||||
#include "os/mutex.h"
|
|
||||||
/**
|
|
||||||
@author Juan Linietsky <red@lunatea>
|
|
||||||
*/
|
|
||||||
class MemoryPoolStaticNedMalloc : public MemoryPoolStatic {
|
|
||||||
|
|
||||||
Mutex *mutex;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
void* alloc(size_t p_bytes,const char *p_description=""); ///< Pointer in p_description shold be to a const char const like "hello"
|
|
||||||
void* realloc(void *p_memory,size_t p_bytes); ///< Pointer in
|
|
||||||
void free(void *p_ptr); ///< Pointer in p_description shold be to a const char const
|
|
||||||
virtual size_t get_available_mem() const;
|
|
||||||
virtual size_t get_total_usage();
|
|
||||||
|
|
||||||
/* Most likely available only if memory debugger was compiled in */
|
|
||||||
virtual int get_alloc_count();
|
|
||||||
virtual void * get_alloc_ptr(int p_alloc_idx);
|
|
||||||
virtual const char* get_alloc_description(int p_alloc_idx);
|
|
||||||
virtual size_t get_alloc_size(int p_alloc_idx);
|
|
||||||
|
|
||||||
virtual void debug_print_all_memory();
|
|
||||||
|
|
||||||
MemoryPoolStaticNedMalloc();
|
|
||||||
~MemoryPoolStaticNedMalloc();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,302 +0,0 @@
|
||||||
#ifdef NEDMALLOC_ENABLED
|
|
||||||
|
|
||||||
/* nedalloc, an alternative malloc implementation for multiple threads without
|
|
||||||
lock contention based on dlmalloc v2.8.3. (C) 2005-2009 Niall Douglas
|
|
||||||
|
|
||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute,
|
|
||||||
execute, and transmit the Software, and to prepare derivative works of the
|
|
||||||
Software, and to permit third-parties to whom the Software is furnished to
|
|
||||||
do so, all subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer,
|
|
||||||
must be included in all copies of the Software, in whole or in part, and
|
|
||||||
all derivative works of the Software, unless such copies or derivative
|
|
||||||
works are solely in the form of machine-executable object code generated by
|
|
||||||
a source language processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
||||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NEDMALLOC_H
|
|
||||||
#define NEDMALLOC_H
|
|
||||||
|
|
||||||
#include "typedefs.h"
|
|
||||||
#define MALLOC_ALIGNMENT DEFAULT_ALIGNMENT
|
|
||||||
|
|
||||||
#ifdef PSP_ENABLED
|
|
||||||
#define USE_LOCKS 0
|
|
||||||
#define HAVE_MMAP 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* See malloc.c.h for what each function does.
|
|
||||||
|
|
||||||
REPLACE_SYSTEM_ALLOCATOR on POSIX causes nedalloc's functions to be called
|
|
||||||
malloc, free etc. instead of nedmalloc, nedfree etc. You may or may not want
|
|
||||||
this. On Windows it causes nedmalloc to patch all loaded DLLs and binaries
|
|
||||||
to replace usage of the system allocator.
|
|
||||||
|
|
||||||
NO_NED_NAMESPACE prevents the functions from being defined in the nedalloc
|
|
||||||
namespace when in C++ (uses the global namespace instead).
|
|
||||||
|
|
||||||
NEDMALLOCEXTSPEC can be defined to be __declspec(dllexport) or
|
|
||||||
__attribute__ ((visibility("default"))) or whatever you like. It defaults
|
|
||||||
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,
|
|
||||||
ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER.
|
|
||||||
|
|
||||||
NEDMALLOC_DEBUG can be defined to cause DEBUG to be set differently for nedmalloc
|
|
||||||
than for the rest of the build. Remember to set NDEBUG to disable all assertion
|
|
||||||
checking too.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
ENABLE_TOLERANT_NEDMALLOC is automatically turned on if REPLACE_SYSTEM_ALLOCATOR
|
|
||||||
is set or the Windows DLL is being built. This causes nedmalloc to detect when a
|
|
||||||
system allocator block is passed to it and to handle it appropriately. Note that
|
|
||||||
without USE_MAGIC_HEADERS there is a very tiny chance that nedmalloc will segfault
|
|
||||||
on non-Windows builds (it uses Win32 SEH to trap segfaults on Windows and there
|
|
||||||
is no comparable system on POSIX).
|
|
||||||
|
|
||||||
USE_ALLOCATOR can be one of these settings (it defaults to 1):
|
|
||||||
0: System allocator (nedmalloc now simply acts as a threadcache).
|
|
||||||
WARNING: Intended for DEBUG USE ONLY - not all functions work correctly.
|
|
||||||
1: dlmalloc
|
|
||||||
|
|
||||||
ENABLE_LARGE_PAGES enables support for requesting memory from the system in large
|
|
||||||
(typically >=2Mb) pages if the host OS supports this. These occupy just a single
|
|
||||||
TLB entry and can significantly improve performance in large working set applications.
|
|
||||||
|
|
||||||
ENABLE_FAST_HEAP_DETECTION enables special logic to detect blocks allocated
|
|
||||||
by the system heap. This avoids 1.5%-2% overhead when checking for non-nedmalloc
|
|
||||||
blocks, but it assumes that the NT and glibc heaps function in a very specific
|
|
||||||
fashion which may not hold true across OS upgrades.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h> /* for size_t */
|
|
||||||
|
|
||||||
#ifndef NEDMALLOCEXTSPEC
|
|
||||||
#ifdef NEDMALLOC_DLL_EXPORTS
|
|
||||||
#ifdef WIN32
|
|
||||||
#define NEDMALLOCEXTSPEC extern __declspec(dllexport)
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#define NEDMALLOCEXTSPEC extern __attribute__ ((visibility("default")))
|
|
||||||
#endif
|
|
||||||
#ifndef ENABLE_TOLERANT_NEDMALLOC
|
|
||||||
#define ENABLE_TOLERANT_NEDMALLOC 1
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define NEDMALLOCEXTSPEC extern
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __STDC_VERSION__ >= 199901L /* C99 or better */
|
|
||||||
#define RESTRICT restrict
|
|
||||||
#else
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER>=1400
|
|
||||||
#define RESTRICT __restrict
|
|
||||||
#endif
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define RESTRICT __restrict
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#ifndef RESTRICT
|
|
||||||
#define RESTRICT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER>=1400
|
|
||||||
#define NEDMALLOCPTRATTR __declspec(restrict)
|
|
||||||
#define NEDMALLOCNOALIASATTR __declspec(noalias)
|
|
||||||
#endif
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define NEDMALLOCPTRATTR __attribute__ ((malloc))
|
|
||||||
#endif
|
|
||||||
#ifndef NEDMALLOCPTRATTR
|
|
||||||
#define NEDMALLOCPTRATTR
|
|
||||||
#endif
|
|
||||||
#ifndef NEDMALLOCNOALIASATTR
|
|
||||||
#define NEDMALLOCNOALIASATTR
|
|
||||||
#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
|
|
||||||
#if USE_ALLOCATOR==0
|
|
||||||
#error Cannot combine using the system allocator with replacing the system allocator
|
|
||||||
#endif
|
|
||||||
#ifndef ENABLE_TOLERANT_NEDMALLOC
|
|
||||||
#define ENABLE_TOLERANT_NEDMALLOC 1
|
|
||||||
#endif
|
|
||||||
#ifndef WIN32 /* We have a dedicated patcher for Windows */
|
|
||||||
#define nedmalloc malloc
|
|
||||||
#define nedcalloc calloc
|
|
||||||
#define nedrealloc realloc
|
|
||||||
#define nedfree free
|
|
||||||
#define nedmemalign memalign
|
|
||||||
#define nedmallinfo mallinfo
|
|
||||||
#define nedmallopt mallopt
|
|
||||||
#define nedmalloc_trim malloc_trim
|
|
||||||
#define nedmalloc_stats malloc_stats
|
|
||||||
#define nedmalloc_footprint malloc_footprint
|
|
||||||
#define nedindependent_calloc independent_calloc
|
|
||||||
#define nedindependent_comalloc independent_comalloc
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define nedblksize _msize
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
struct nedmallinfo {
|
|
||||||
size_t arena; /* non-mmapped space allocated from system */
|
|
||||||
size_t ordblks; /* number of free chunks */
|
|
||||||
size_t smblks; /* always 0 */
|
|
||||||
size_t hblks; /* always 0 */
|
|
||||||
size_t hblkhd; /* space in mmapped regions */
|
|
||||||
size_t usmblks; /* maximum total allocated space */
|
|
||||||
size_t fsmblks; /* always 0 */
|
|
||||||
size_t uordblks; /* total allocated space */
|
|
||||||
size_t fordblks; /* total free space */
|
|
||||||
size_t keepcost; /* releasable (via malloc_trim) space */
|
|
||||||
};
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
#if !defined(NO_NED_NAMESPACE)
|
|
||||||
namespace nedalloc {
|
|
||||||
#else
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
#define THROWSPEC throw()
|
|
||||||
#else
|
|
||||||
#define THROWSPEC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* These are the global functions */
|
|
||||||
|
|
||||||
/* Gets the usable size of an allocated block. Note this will always be bigger than what was
|
|
||||||
asked for due to rounding etc. Optionally returns 1 in isforeign if the block came from the
|
|
||||||
system allocator - note that there is a small (>0.01%) but real chance of segfault on non-Windows
|
|
||||||
systems when passing non-nedmalloc blocks if you don't use USE_MAGIC_HEADERS.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR size_t nedblksize(int *RESTRICT isforeign, void *RESTRICT mem) THROWSPEC;
|
|
||||||
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void nedsetvalue(void *v) THROWSPEC;
|
|
||||||
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmalloc(size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedcalloc(size_t no, size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedrealloc(void *mem, size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void nedfree(void *mem) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR struct nedmallinfo nedmallinfo(void) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR int nedmallopt(int parno, int value) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR void* nedmalloc_internals(size_t *granularity, size_t *magic) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR int nedmalloc_trim(size_t pad) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC void nedmalloc_stats(void) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR size_t nedmalloc_footprint(void) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCNOALIASATTR NEDMALLOCPTRATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
|
||||||
|
|
||||||
/* Destroys the system memory pool used by the functions above.
|
|
||||||
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
|
|
||||||
get a fatal exception!
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void neddestroysyspool() THROWSPEC;
|
|
||||||
|
|
||||||
/* These are the pool functions */
|
|
||||||
struct nedpool_t;
|
|
||||||
typedef struct nedpool_t nedpool;
|
|
||||||
|
|
||||||
/* Creates a memory pool for use with the nedp* functions below.
|
|
||||||
Capacity is how much to allocate immediately (if you know you'll be allocating a lot
|
|
||||||
of memory very soon) which you can leave at zero. Threads specifies how many threads
|
|
||||||
will *normally* be accessing the pool concurrently. Setting this to zero means it
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC;
|
|
||||||
|
|
||||||
/* Destroys a memory pool previously created by nedcreatepool().
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void neddestroypool(nedpool *p) THROWSPEC;
|
|
||||||
|
|
||||||
/* Returns a zero terminated snapshot of threadpools existing at the time of call. Call
|
|
||||||
nedfree() on the returned list when you are done. Returns zero if there is only the
|
|
||||||
system pool in existence.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC nedpool **nedpoollist() THROWSPEC;
|
|
||||||
|
|
||||||
/* Sets a value to be associated with a pool. You can retrieve this value by passing
|
|
||||||
any memory block allocated from that pool.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void nedpsetvalue(nedpool *p, void *v) THROWSPEC;
|
|
||||||
|
|
||||||
/* Gets a previously set value using nedpsetvalue() or zero if memory is unknown.
|
|
||||||
Optionally can also retrieve pool. You can detect an unknown block by the return
|
|
||||||
being zero and *p being unmodifed.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void *nedgetvalue(nedpool **p, void *mem) THROWSPEC;
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
system pool. Setting disable to non-zero replicates neddisablethreadcache().
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void nedtrimthreadcache(nedpool *p, int disable) THROWSPEC;
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
system pool.
|
|
||||||
*/
|
|
||||||
NEDMALLOCEXTSPEC void neddisablethreadcache(nedpool *p) THROWSPEC;
|
|
||||||
|
|
||||||
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpmalloc(nedpool *p, size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC void nedpfree(nedpool *p, void *mem) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC struct nedmallinfo nedpmallinfo(nedpool *p) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC void nedpmalloc_stats(nedpool *p) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC size_t nedpmalloc_footprint(nedpool *p) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC;
|
|
||||||
NEDMALLOCEXTSPEC NEDMALLOCPTRATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC;
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -34,7 +34,6 @@ def get_flags():
|
||||||
|
|
||||||
return [
|
return [
|
||||||
('tools', 'no'),
|
('tools', 'no'),
|
||||||
('nedmalloc', 'no'),
|
|
||||||
('builtin_zlib', 'no'),
|
('builtin_zlib', 'no'),
|
||||||
('openssl', 'builtin'), #use builtin openssl
|
('openssl', 'builtin'), #use builtin openssl
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,9 +32,7 @@ def get_opts():
|
||||||
def get_flags():
|
def get_flags():
|
||||||
|
|
||||||
return [
|
return [
|
||||||
('lua', 'no'),
|
|
||||||
('tools', 'no'),
|
('tools', 'no'),
|
||||||
('nedmalloc', 'no'),
|
|
||||||
('theora', 'no'),
|
('theora', 'no'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -25,20 +25,11 @@ def get_opts():
|
||||||
def get_flags():
|
def get_flags():
|
||||||
|
|
||||||
return [
|
return [
|
||||||
('lua', 'no'),
|
|
||||||
('tools', 'no'),
|
('tools', 'no'),
|
||||||
('nedmalloc', 'no'),
|
|
||||||
('theora', 'no'),
|
('theora', 'no'),
|
||||||
('tools', 'no'),
|
|
||||||
('nedmalloc', 'no'),
|
|
||||||
('musepack', 'no'),
|
('musepack', 'no'),
|
||||||
('squirrel', 'no'),
|
|
||||||
('squish', 'no'),
|
('squish', 'no'),
|
||||||
('old_scenes', 'no'),
|
|
||||||
('etc1', 'no'),
|
('etc1', 'no'),
|
||||||
# ('default_gui_theme', 'no'),
|
|
||||||
|
|
||||||
#('builtin_zlib', 'no'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "drivers/gles2/rasterizer_gles2.h"
|
#include "drivers/gles2/rasterizer_gles2.h"
|
||||||
|
|
||||||
#include "os_windows.h"
|
#include "os_windows.h"
|
||||||
#include "drivers/nedmalloc/memory_pool_static_nedmalloc.h"
|
|
||||||
#include "drivers/unix/memory_pool_static_malloc.h"
|
#include "drivers/unix/memory_pool_static_malloc.h"
|
||||||
#include "os/memory_pool_dynamic_static.h"
|
#include "os/memory_pool_dynamic_static.h"
|
||||||
#include "drivers/windows/thread_windows.h"
|
#include "drivers/windows/thread_windows.h"
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
#include "drivers/gles2/rasterizer_gles2.h"
|
#include "drivers/gles2/rasterizer_gles2.h"
|
||||||
#include "os_winrt.h"
|
#include "os_winrt.h"
|
||||||
#include "drivers/nedmalloc/memory_pool_static_nedmalloc.h"
|
|
||||||
#include "drivers/unix/memory_pool_static_malloc.h"
|
#include "drivers/unix/memory_pool_static_malloc.h"
|
||||||
#include "os/memory_pool_dynamic_static.h"
|
#include "os/memory_pool_dynamic_static.h"
|
||||||
#include "thread_winrt.h"
|
#include "thread_winrt.h"
|
||||||
|
|
Loading…
Reference in a new issue