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 /*--- prototypes -------------------------------------------------------*/
|
|
39
|
|
40 BEGIN_C_DECLS
|
|
41
|
|
42
|
|
43
|
|
44 /* Allocation related functions and macros: */
|
|
45
|
|
46 /* Builds and initializes all needed datastructures of the new allocator. */
|
|
47 void init_mc_allocator (void);
|
|
48
|
|
49 /* Returns a pointer to a block of memory of given size on the used heap. */
|
|
50 void *mc_alloc (size_t size);
|
|
51
|
|
52 /* Frees the object pointed to by pointer. */
|
|
53 void mc_free (void *ptr);
|
|
54
|
|
55 /* Modifies the size of the memory block pointed to by ptr. The
|
|
56 Address of the new block of given size is returned. */
|
|
57 void *mc_realloc (void *ptr, size_t size);
|
|
58
|
|
59
|
|
60
|
|
61 /* Garbage collection related functions and macros: */
|
|
62
|
|
63 /* Set the mark bit of the object pointed to by ptr to value.*/
|
|
64 void set_mark_bit (void *ptr, EMACS_INT value);
|
|
65
|
|
66 /* Return the mark bit of the object pointed to by ptr. */
|
|
67 EMACS_INT get_mark_bit (void *ptr);
|
|
68
|
|
69 /* mark bit macros */
|
|
70 /* Returns true if the mark bit of the object pointed to by ptr is set. */
|
|
71 #define MARKED_P(ptr) (get_mark_bit (ptr) == 1)
|
|
72
|
|
73 /* Marks the object pointed to by ptr (sets the mark bit to 1). */
|
|
74 #define MARK(ptr) set_mark_bit (ptr, 1)
|
|
75
|
|
76 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */
|
|
77 #define UNMARK(ptr) set_mark_bit (ptr, 0)
|
|
78
|
|
79 /* The finalizer of every not marked object is called. The macro
|
|
80 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of
|
|
81 the object. */
|
|
82 void mc_finalize (void);
|
|
83
|
|
84 /* All not marked objects of the used heap are freed. */
|
|
85 void mc_sweep (void);
|
|
86
|
|
87
|
|
88
|
|
89 /* Portable dumper related functions and macros: */
|
|
90
|
|
91 /* The finalizer for disksave of every object is called to shrink the
|
|
92 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to
|
|
93 be defined and call the finalizer for disksave of the object. */
|
|
94 void mc_finalize_for_disksave (void);
|
|
95
|
|
96
|
|
97
|
|
98 /* Allocation function for the unmanaged heap: */
|
|
99
|
|
100 /* Returns a pointer to a block of memory of given size on the
|
|
101 unmanaged heap. */
|
|
102 void *mc_alloc_unmanaged (size_t size);
|
|
103
|
|
104 /* Modifies the size of the memory block pointed to by ptr. The
|
|
105 Address of the new block of given size is returned. */
|
|
106 void *mc_realloc_unmanaged (void *ptr, size_t size);
|
|
107
|
|
108
|
|
109
|
|
110 /* Functions and macros related with allocation statistics: */
|
|
111
|
|
112 #ifdef MEMORY_USAGE_STATS
|
|
113 /* Returns the real size, including overhead, which is actually alloced
|
|
114 for an object with given claimed_size. */
|
|
115 Bytecount mc_alloced_storage_size (Bytecount claimed_size,
|
|
116 struct overhead_stats *stats);
|
|
117 #endif /* MEMORY_USAGE_STATS */
|
|
118
|
|
119 END_C_DECLS
|
|
120
|
|
121 #endif /* INCLUDED_mc_alloc_h_ */
|