Now handles multiple hosts and targets.
[deliverable/binutils-gdb.git] / gdb / gmalloc.h
CommitLineData
dd3b648e
RP
1/* Declarations for `malloc' and friends.
2 Copyright 1990 Free Software Foundation
3 Written May 1989 by Mike Haertel.
4
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)
8 any later version.
9
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.
14
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.
18
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. */
21
22#ifndef _MALLOC_H
23
24#define _MALLOC_H 1
25
26#ifndef __ONEFILE
27#define __need_NULL
28#define __need_size_t
29#define __need_ptrdiff_t
30#include <stddef.h>
31#endif
32
33#ifdef _MALLOC_INTERNAL
34
35#ifndef __ONEFILE
36#include <limits.h>
37#endif
38
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)
48
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)
52
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
56
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
60 run faster. */
61#define MALLOC_SEARCH_START _heapindex
62
63/* Data structure giving per-block information. */
64typedef union
65 {
66 /* Heap information for a busy block. */
67 struct
68 {
69 /* Zero for a large block, or positive giving the
70 logarithm to the base two of the fragment size. */
71 int type;
72 union
73 {
74 struct
75 {
76 size_t nfree; /* Free fragments in a fragmented block. */
77 size_t first; /* First free fragment of the block. */
78 } frag;
79 /* Size (in blocks) of a large cluster. */
80 size_t size;
81 } info;
82 } busy;
83 /* Heap information for a free block (that may be the first of
84 a free cluster). */
85 struct
86 {
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. */
90 } free;
91 } malloc_info;
92
93/* Pointer to first block of the heap. */
94extern char *_heapbase;
95
96/* Table indexed by block number giving per-block information. */
97extern malloc_info *_heapinfo;
98
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))
102
103/* Current search index for the heap table. */
104extern size_t _heapindex;
105
106/* Limit of valid info table indices. */
107extern size_t _heaplimit;
108
109/* Doubly linked lists of free fragments. */
110struct list
111 {
112 struct list *next;
113 struct list *prev;
114 };
115
116/* Free list headers for each fragment size. */
117extern struct list _fraghead[];
118
119/* Instrumentation. */
120extern size_t _chunks_used;
121extern size_t _bytes_used;
122extern size_t _chunks_free;
123extern size_t _bytes_free;
124
125/* Internal version of free() used in morecore(). */
126extern void EXFUN(__free, (PTR __ptr));
127
128#endif /* _MALLOC_INTERNAL. */
129
130/* Underlying allocation function; successive calls should
131 return contiguous pieces of memory. */
132extern PTR EXFUN((*__morecore), (ptrdiff_t __size));
133
134/* Default value of previous. */
135extern PTR EXFUN(__default_morecore, (ptrdiff_t __size));
136
137/* Flag whether malloc has been called. */
138extern int __malloc_initialized;
139
140/* Hooks for debugging versions. */
141extern void EXFUN((*__free_hook), (PTR __ptr));
142extern PTR EXFUN((*__malloc_hook), (size_t __size));
143extern PTR EXFUN((*__realloc_hook), (PTR __ptr, size_t __size));
144
145/* Activate a standard collection of debugging hooks. */
146extern void EXFUN(mcheck, (void EXFUN((*func), (void))));
147
148/* Statistics available to the user. */
149struct mstats
150 {
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. */
156 };
157
158/* Pick up the current statistics. */
159extern struct mstats EXFUN(mstats, (NOARGS));
160
161#endif /* malloc.h */
This page took 0.035438 seconds and 4 git commands to generate.