1 /* table.h - definitions for tables for keeping track of allocated memory */
3 /* Copyright (C) 2001 Free Software Foundation, Inc.
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 2, 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
24 #ifdef MALLOC_REGISTER
26 /* values for flags byte. */
33 * MEM is the address of the allocated pointer.
34 * SIZE is the requested allocation size.
35 * FLAGS includes either MT_ALLOC (MEM is allocated) or MT_FREE (MEM is
36 * not allocated). Other flags later.
37 * FUNC is set to the name of the function doing the allocation (from the
38 * `tag' argument to register_alloc().
39 * FILE and LINE are the filename and line number of the last allocation
40 * and free (depending on STATUS) of MEM.
41 * NALLOC and NFREE are incremented on each allocation that returns MEM or
42 * each free of MEM, respectively (way to keep track of memory reuse
43 * and how well the free lists are working).
46 typedef struct mr_table {
56 #define REG_TABLE_SIZE 8192
58 extern mr_table_t *mr_table_entry __P((PTR_T));
59 extern void mregister_alloc __P((const char *, PTR_T, size_t, const char *, int));
60 extern void mregister_free __P((PTR_T, int, const char *, int));
61 extern void mregister_describe_mem ();
62 extern void mregister_dump_table __P((void));
63 extern void mregister_table_init __P((void));
65 /* NOTE: HASH_MIX taken from dmalloc (http://dmalloc.com) */
72 * Mix 3 32-bit values reversibly. For every delta with one or two
73 * bits set, and the deltas of all three high bits or all three low
74 * bits, whether the original value of a,b,c is almost all zero or is
75 * uniformly distributed.
77 * If HASH_MIX() is run forward or backward, at least 32 bits in a,b,c
78 * have at least 1/4 probability of changing. If mix() is run
79 * forward, every bit of c will change between 1/3 and 2/3 of the
80 * time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
82 * HASH_MIX() takes 36 machine instructions, but only 18 cycles on a
83 * superscalar machine (like a Pentium or a Sparc). No faster mixer
84 * seems to work, that's the result of my brute-force search. There
85 * were about 2^68 hashes to choose from. I only tested about a
88 #define HASH_MIX(a, b, c) \
90 a -= b; a -= c; a ^= (c >> 13); \
91 b -= c; b -= a; b ^= (a << 8); \
92 c -= a; c -= b; c ^= (b >> 13); \
93 a -= b; a -= c; a ^= (c >> 12); \
94 b -= c; b -= a; b ^= (a << 16); \
95 c -= a; c -= b; c ^= (b >> 5); \
96 a -= b; a -= c; a ^= (c >> 3); \
97 b -= c; b -= a; b ^= (a << 10); \
98 c -= a; c -= b; c ^= (b >> 15); \
101 #endif /* MALLOC_REGISTER */
103 #endif /* _MTABLE_H */