annotate src/mc-alloc.h @ 2762:e20ee26d2313

[xemacs-hg @ 2005-05-08 11:37:41 by malcolmp] sysdep.c: Use autoconf 2.59's HAVE_DECL_SYS_SIGLIST instead of SYS_SIGLIST_DECLARED.
author malcolmp
date Sun, 08 May 2005 11:37:42 +0000
parents 6fa9919a9a0b
children ec5f23ea6d2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1 /* New allocator for XEmacs.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2 Copyright (C) 2005 Marcus Crestani.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
3
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
4 This file is part of XEmacs.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
5
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
9 later version.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
10
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
14 for more details.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
15
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
20
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
22
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
23 #ifndef INCLUDED_mc_alloc_h_
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
24 #define INCLUDED_mc_alloc_h_
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
25
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
26
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
27 /* This is moved here from alloc.c. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
28 #ifndef MALLOC_OVERHEAD
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
29 # ifdef GNU_MALLOC
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
30 # define MALLOC_OVERHEAD 0
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
31 # elif defined (rcheck)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
32 # define MALLOC_OVERHEAD 20
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
33 # else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
34 # define MALLOC_OVERHEAD 8
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
35 # endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
36 #endif /* MALLOC_OVERHEAD */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
37
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
38
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
39 /* This enables type based information (updated during gc). The output
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
40 is used by show-memory-usage to print memory information for each
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
41 type. Since the new allocator does not distinguish between types
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
42 anymore, this functionality is additionally implemented and
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
43 consumes a lot of time. That is why it is kept conditioned on a
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
44 separate flag called MC_ALLOC_TYPE_STATS. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
45 #if 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
46 # define MC_ALLOC_TYPE_STATS 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
47 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
48
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
49
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
50 /*--- prototypes -------------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
51
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
52 BEGIN_C_DECLS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
53
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
54
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
55
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
56 /* Allocation related functions and macros: */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
57
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
58 /* Builds and initializes all needed datastructures of the new allocator. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
59 void init_mc_allocator (void);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
60
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
61 /* Returns a pointer to a block of memory of given size on the used heap. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
62 void *mc_alloc (size_t size);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
63
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
64 /* Frees the object pointed to by pointer. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
65 void mc_free (void *ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
66
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
67 /* Modifies the size of the memory block pointed to by ptr. The
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
68 Address of the new block of given size is returned. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
69 void *mc_realloc (void *ptr, size_t size);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
70
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
71
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
72
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
73 /* Garbage collection related functions and macros: */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
74
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
75 /* Set the mark bit of the object pointed to by ptr to value.*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
76 void set_mark_bit (void *ptr, EMACS_INT value);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
77
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
78 /* Return the mark bit of the object pointed to by ptr. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
79 EMACS_INT get_mark_bit (void *ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
80
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
81 /* mark bit macros */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
82 /* Returns true if the mark bit of the object pointed to by ptr is set. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
83 #define MARKED_P(ptr) (get_mark_bit (ptr) == 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
84
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
85 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
86 #define MARK(ptr) set_mark_bit (ptr, 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
87
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
88 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
89 #define UNMARK(ptr) set_mark_bit (ptr, 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
90
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
91 /* The finalizer of every not marked object is called. The macro
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
92 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
93 the object. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
94 void mc_finalize (void);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
95
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
96 /* All not marked objects of the used heap are freed. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
97 void mc_sweep (void);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
98
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
99
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
100
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
101 /* Portable dumper related functions and macros: */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
102
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
103 /* The finalizer for disksave of every object is called to shrink the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
104 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
105 be defined and call the finalizer for disksave of the object. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
106 void mc_finalize_for_disksave (void);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
107
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
108
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
109
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
110 /* Allocation function for the unmanaged heap: */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
111
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
112 /* Returns a pointer to a block of memory of given size on the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
113 unmanaged heap. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
114 void *mc_alloc_unmanaged (size_t size);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
115
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
116 /* Modifies the size of the memory block pointed to by ptr. The
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
117 Address of the new block of given size is returned. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
118 void *mc_realloc_unmanaged (void *ptr, size_t size);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
119
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
120
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
121
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
122 /* Functions and macros related with allocation statistics: */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
123
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
124 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
125 /* Returns the real size, including overhead, which is actually alloced
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
126 for an object with given claimed_size. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
127 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
128 struct overhead_stats *stats);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
129 #endif /* MEMORY_USAGE_STATS */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
130
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
131 END_C_DECLS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
132
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
133 #endif /* INCLUDED_mc_alloc_h_ */