Lines Matching +full:- +full:- +full:disable +full:- +full:malloc +full:- +full:trim

2   A version of malloc/free/realloc written by Doug Lea and released to the
8 Note: There may be an updated version of this malloc obtainable at
9 ftp://g.oswego.edu/pub/misc/malloc.c
12 * Why use this malloc?
14 This is not the fastest, most space-conserving, most portable, or
15 most tunable malloc ever written. However it is among the fastest
16 while also being among the most space-conserving, portable and tunable.
17 Consistent balance across these factors results in a good general-purpose
18 allocator. For a high-level description, see
19 http://g.oswego.edu/dl/html/malloc.html
25 malloc(size_t n);
34 the same as p. If p is null, equivalent to malloc. Unless the
36 size argument of zero (re)allocates a minimum-sized chunk.
46 Equivalent to valloc(minimum-page-that-holds(n)), that is,
54 Release all but pad bytes of freed top-most memory back
70 Alignment: 8-byte
75 Code for 8-byte pointers is untested by me but has worked
86 Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead)
87 8-byte ptrs: 24/32 bytes (including, 4/8 overhead)
95 Even a request for zero bytes (i.e., malloc(0)) returns a
98 Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes
99 8-byte size_t: 2^63 - 16 bytes
112 make the normal worst-case wastage 15 bytes (i.e., up to 15
113 more bytes will be allocated than were requested in malloc), with
115 1. Because requests for zero bytes allocate non-zero space,
125 * No user-definable hooks for callbacks and the like.
130 * Synopsis of compile-time options:
132 People have reported using previous versions of this malloc on all
136 People have also reported adapting this malloc for use in
137 stand-alone embedded systems.
139 The implementation is in straight, hand-tuned ANSI C. Among other
142 (for example gcc -O2) that can simplify expressions and control
146 Nonzero if using ANSI-standard C compiler, a C++ compiler, or
149 Define to enable debugging. Adds fairly extensive assertion-based
154 to free(p). Otherwise, since malloc returns a unique pointer for
155 malloc(0), so does realloc(p, 0).
166 Define to non-zero to optionally make malloc() use mmap() to
169 Define to non-zero to optionally make realloc() use mremap() to
174 Optionally define if you are on a system with a /usr/include/malloc.h
178 Define to a 32-bit type (probably `unsigned int') if you are on a
179 64-bit machine, yet do not want or need to allow malloc requests of
184 Also note that there is some odd internal name-mangling via defines
185 (for example, internally, `malloc' is named `mALLOc') needed
196 MORECORE_FAILURE (default: -1)
254 #if 0 /* not for U-Boot */
260 Compile-time options
268 malloc will often die when freed memory is overwritten by user
272 If you compile with -DDEBUG, a number of assertion checks are
278 attempt to check every non-mmapped allocated and free chunk in the
289 INTERNAL_SIZE_T is the word-size used for internal bookkeeping
290 of chunk sizes. On a 64-bit machine, you can reduce malloc
304 Some people think it should. Otherwise, since this malloc
305 returns a unique pointer for malloc(0), so does realloc(p, 0).
314 mmap-based options are not currently supported in WIN32.
379 /* The following macros are only invoked with (2n+1)-multiples of
426 if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \
435 case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \
444 if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \
453 case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \
461 Define HAVE_MMAP to optionally make malloc() use mmap() to
471 #undef HAVE_MMAP /* Not available for U-Boot */
474 Define HAVE_MREMAP to make realloc() use mremap() to re-allocate
488 #undef HAVE_MREMAP /* Not available for U-Boot */
503 Access to system page size. To the extent possible, this malloc
504 manages memory from the system in page-size units.
510 #define LACKS_UNISTD_H /* Shortcut for U-Boot */
565 This version of malloc supports the standard SVID/XPG mallinfo
568 any SVID/XPG compliant system that has a /usr/include/malloc.h
571 and below and save them in a malloc.h file. But there's no
575 (by-copy) by mallinfo(). The SVID/XPG malloinfo struct contains a
577 version of malloc. Some of these fields are are instead filled by
581 /usr/include/malloc.h file that includes a declaration of struct
591 #include "/usr/include/malloc.h"
598 int ordblks; /* number of non-inuse chunks */
599 int smblks; /* unused -- always zero */
602 int usmblks; /* unused -- always zero */
603 int fsmblks; /* unused -- always zero */
605 int fordblks; /* total non-inuse space */
606 int keepcost; /* top-most, releasable (via malloc_trim) space */
611 #define M_MXFAST 1 /* UNUSED in this malloc */
612 #define M_NLBLKS 2 /* UNUSED in this malloc */
613 #define M_GRAIN 3 /* UNUSED in this malloc */
614 #define M_KEEP 4 /* UNUSED in this malloc */
620 #define M_TRIM_THRESHOLD -1
621 #define M_TOP_PAD -2
622 #define M_MMAP_THRESHOLD -3
623 #define M_MMAP_MAX -4
631 M_TRIM_THRESHOLD is the maximum amount of unused top-most memory
634 Automatic trimming is mainly useful in long-lived programs.
641 The trim threshold and the mmap control parameters (see below)
645 system-level demands of a long-lived program down to a bare
647 the XF86 X server on Linux, using a trim threshold of 128K and a
648 mmap threshold of 192K led to near-minimal long term resource
651 If you are using this malloc in a long-lived program, it should
660 chunks at all. And in well-behaved long-lived programs,
665 protection against the system-level effects of carrying around
671 The default trim value is high enough to cause trimming only in
674 disable trimming completely, you can set to (unsigned long)(-1);
689 a new malloc request, this much padding is added to the sbrk
700 that nearly every malloc request during program start-up (or
704 Automatic rounding-up to page-size units is normally sufficient
721 be allocated using already-existing space will be serviced via mmap.
732 helps keep the system level memory demands of a long-lived
743 3. It causes malloc performance to be more dependent on host
747 malloc steps is faster than going through a system's mmap.
773 better off using normal sbrk-based allocation routines that
779 the default value is 0, and attempts to set it to non-zero values
799 using weak aliases, this malloc is NOT designed to work in
801 control are provided to ensure that multiple malloc or free calls
803 semaphore could be used across malloc, realloc, and free (which is
841 #define MORECORE_FAILURE -1
854 #define mALLOc __libc_malloc macro
865 #pragma weak malloc = __libc_malloc macro
876 #define malloc malloc_simple macro
889 # define mALLOc dlmalloc macro
899 # define mALLOc malloc macro
910 /* Set up pre-relocation malloc() ready for use */
921 Void_t* mALLOc(size_t);
935 Void_t* mALLOc();
953 * Begin and End of memory area for malloc(), and current "brk"