integrate dlmalloc etc. with ppremake

This commit is contained in:
David Rose 2005-09-30 15:41:50 +00:00
parent f57fe99b6a
commit 5f3b0fc55b
4 changed files with 59 additions and 3 deletions

View File

@ -326,6 +326,16 @@
// increase run-time overhead.
#defer DO_PIPELINING $[<= $[OPTIMIZE], 1]
// Do you want to use one of the alternative malloc implementations?
// This is almost always a good idea on Windows, where the standard
// malloc implementation appears to be pretty poor, but probably
// doesn't matter much on Linux (which is likely to implement
// ptmalloc2 anyway). We always define this by default on Windows; on
// Linux, we define it by default only when DO_MEMORY_USAGE is enabled
// (since in that case, we'll be paying the overhead for the extra
// call anyway).
#defer ALTERNATIVE_MALLOC $[or $[WINDOWS_PLATFORM],$[DO_MEMORY_USAGE]]
// Is NSPR installed, and where? This is the Netscape Portable
// Runtime library, downloadable as part of the Mozilla package from
// mozilla.org. It provides portable threading and networking

View File

@ -431,6 +431,34 @@ $[cdefine HAVE_RTTI]
/* Must global operator new and delete functions throw exceptions? */
$[cdefine GLOBAL_OPERATOR_NEW_EXCEPTIONS]
/* Which memory allocation scheme should we use? */
#define USE_MEMORY_DLMALLOC
#define USE_MEMORY_PTMALLOC2
#define USE_MEMORY_MALLOC
#define USE_MEMORY_NOWRAPPERS
#if $[ALTERNATIVE_MALLOC]
#if $[HAVE_THREADS]
// A fast thread-safe alternative implementation.
#set USE_MEMORY_PTMALLOC2 1
#else
// A faster, but non-thread-safe, alternative implementation.
#set USE_MEMORY_DLMALLOC 1
#endif
#else
#if $[DO_MEMORY_USAGE]
// Redefine new and delete to malloc(), and also provide hooks for
// the benefit of the MemoryUsage class.
#set USE_MEMORY_MALLOC 1
#else
// Don't redefine new and delete at all.
#set USE_MEMORY_NOWRAPPERS 1
#endif
#endif
$[cdefine USE_MEMORY_DLMALLOC]
$[cdefine USE_MEMORY_PTMALLOC2]
$[cdefine USE_MEMORY_MALLOC]
$[cdefine USE_MEMORY_NOWRAPPERS]
/* What style STL allocator should we declare? */
#define OLD_STYLE_ALLOCATOR
#define GNU_STYLE_ALLOCATOR

View File

@ -29,6 +29,10 @@
#if defined(USE_MEMORY_DLMALLOC)
#ifdef HAVE_THREADS
#error Cannot use dlmalloc library with threading enabled!
#endif
#define USE_DL_PREFIX 1
#define NO_MALLINFO 1
#include "dlmalloc.h"
@ -85,14 +89,14 @@ void (*global_operator_delete)(void *ptr) = &default_operator_delete;
/////////////////////////////////////////////////////////////////////
//
// Memory manager: NONE
// Memory manager: MALLOC
//
// This option uses the built-in system allocator. This is a good
// choice on linux, but it's a terrible choice on windows.
//
/////////////////////////////////////////////////////////////////////
#else
#elif defined(USE_MEMORY_MALLOC)
void *default_operator_new(size_t size) {
void *ptr = malloc(size);
@ -110,4 +114,17 @@ void default_operator_delete(void *ptr) {
void *(*global_operator_new)(size_t size) = &default_operator_new;
void (*global_operator_delete)(void *ptr) = &default_operator_delete;
/////////////////////////////////////////////////////////////////////
//
// Memory manager: NOWRAPPERS
//
// Not only do we use the built-in system definitions for new and
// delete, but we don't even wrap them. This removes a tiny bit of
// extra overhead from the above option, but prevents Panda's
// MemoryUsage class from being able to track memory allocations.
//
/////////////////////////////////////////////////////////////////////
#else
#endif

View File

@ -139,7 +139,7 @@ typedef ios::seekdir ios_seekdir;
// Now redefine global operators new and delete so we can optionally
// provide custom handlers for them. The MemoryUsage class in Panda
// takes advantage of this to track the size of allocated pointers.
#ifndef USE_MEMORY_NOWRAPPERS
EXPCL_DTOOL void *default_operator_new(size_t size);
EXPCL_DTOOL void default_operator_delete(void *ptr);
@ -183,5 +183,6 @@ INLINE void operator delete[](void *ptr) {
}
#endif // GLOBAL_OPERATOR_NEW_EXCEPTIONS
#endif // USE_MEMORY_NOWRAPPERS
#endif