1 /* Declarations for `malloc' and friends.
2 Copyright 1990 Free Software Foundation
3 Written May 1989 by Mike Haertel.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 The author may be reached (Email) at the address mike@@ai.mit.edu,
20 or (US mail) as Mike Haertel c/o Free Software Foundation. */
29 #define __need_ptrdiff_t
33 #ifdef _MALLOC_INTERNAL
39 /* The allocator divides the heap into blocks of fixed size; large
40 requests receive one or more whole blocks, and small requests
41 receive a fragment of a block. Fragment sizes are powers of two,
42 and all fragments of a block are the same size. When all the
43 fragments in a block have been freed, the block itself is freed. */
44 #define INT_BIT (CHAR_BIT * sizeof(int))
45 #define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
46 #define BLOCKSIZE (1 << BLOCKLOG)
47 #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
49 /* Determine the amount of memory spanned by the initial heap table
50 (not an absolute limit). */
51 #define HEAP (INT_BIT > 16 ? 4194304 : 65536)
53 /* Number of contiguous free blocks allowed to build up at the end of
54 memory before they will be returned to the system. */
55 #define FINAL_FREE_BLOCKS 8
57 /* Where to start searching the free list when looking for new memory.
58 The two possible values are 0 and _heapindex. Starting at 0 seems
59 to reduce total memory usage, while starting at _heapindex seems to
61 #define MALLOC_SEARCH_START _heapindex
63 /* Data structure giving per-block information. */
66 /* Heap information for a busy block. */
69 /* Zero for a large block, or positive giving the
70 logarithm to the base two of the fragment size. */
76 size_t nfree
; /* Free fragments in a fragmented block. */
77 size_t first
; /* First free fragment of the block. */
79 /* Size (in blocks) of a large cluster. */
83 /* Heap information for a free block (that may be the first of
87 size_t size
; /* Size (in blocks) of a free cluster. */
88 size_t next
; /* Index of next free cluster. */
89 size_t prev
; /* Index of previous free cluster. */
93 /* Pointer to first block of the heap. */
94 extern char *_heapbase
;
96 /* Table indexed by block number giving per-block information. */
97 extern malloc_info
*_heapinfo
;
99 /* Address to block number and vice versa. */
100 #define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
101 #define ADDRESS(B) ((PTR) (((B) - 1) * BLOCKSIZE + _heapbase))
103 /* Current search index for the heap table. */
104 extern size_t _heapindex
;
106 /* Limit of valid info table indices. */
107 extern size_t _heaplimit
;
109 /* Doubly linked lists of free fragments. */
116 /* Free list headers for each fragment size. */
117 extern struct list _fraghead
[];
119 /* Instrumentation. */
120 extern size_t _chunks_used
;
121 extern size_t _bytes_used
;
122 extern size_t _chunks_free
;
123 extern size_t _bytes_free
;
125 /* Internal version of free() used in morecore(). */
126 extern void EXFUN(__free
, (PTR __ptr
));
128 #endif /* _MALLOC_INTERNAL. */
130 /* Underlying allocation function; successive calls should
131 return contiguous pieces of memory. */
132 extern PTR
EXFUN((*__morecore
), (ptrdiff_t __size
));
134 /* Default value of previous. */
135 extern PTR
EXFUN(__default_morecore
, (ptrdiff_t __size
));
137 /* Flag whether malloc has been called. */
138 extern int __malloc_initialized
;
140 /* Hooks for debugging versions. */
141 extern void EXFUN((*__free_hook
), (PTR __ptr
));
142 extern PTR
EXFUN((*__malloc_hook
), (size_t __size
));
143 extern PTR
EXFUN((*__realloc_hook
), (PTR __ptr
, size_t __size
));
145 /* Activate a standard collection of debugging hooks. */
146 extern void EXFUN(mcheck
, (void EXFUN((*func
), (void))));
148 /* Statistics available to the user. */
151 size_t bytes_total
; /* Total size of the heap. */
152 size_t chunks_used
; /* Chunks allocated by the user. */
153 size_t bytes_used
; /* Byte total of user-allocated chunks. */
154 size_t chunks_free
; /* Chunks in the free list. */
155 size_t bytes_free
; /* Byte total of chunks in the free list. */
158 /* Pick up the current statistics. */
159 extern struct mstats
EXFUN(mstats
, (NOARGS
));
161 #endif /* malloc.h */
This page took 0.032495 seconds and 5 git commands to generate.