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