Mercurial > hg > xemacs-beta
annotate src/mc-alloc.h @ 5184:039d9a7f2e6d
Call init_string_ascii_begin() in #'sort*, #'fill, don't be clever.
2010-04-02 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (FsortX, Ffill):
Don't try to be clever with the ascii_begin string header slot in
these function, just call init_string_ascii_begin().
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 02 Apr 2010 12:31:23 +0100 |
parents | e374ea766cc1 |
children | 308d34e9f07d |
rev | line source |
---|---|
2720 | 1 /* New allocator for XEmacs. |
2 Copyright (C) 2005 Marcus Crestani. | |
5167
e374ea766cc1
clean up, rearrange allocation statistics code
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
3 Copyright (C) 2010 Ben Wing. |
2720 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 #ifndef INCLUDED_mc_alloc_h_ | |
25 #define INCLUDED_mc_alloc_h_ | |
26 | |
27 /*--- prototypes -------------------------------------------------------*/ | |
28 | |
29 BEGIN_C_DECLS | |
30 | |
3305 | 31 /* Set to 1 if memory becomes short. */ |
32 extern EMACS_INT memory_shortage; | |
2720 | 33 |
34 | |
3092 | 35 /* Internal Allocator Functions: */ |
2720 | 36 |
3092 | 37 /* Initialize the allocator. This has to be called prior to |
38 requesting memory. */ | |
2720 | 39 void init_mc_allocator (void); |
40 | |
3092 | 41 /* Allocate a block of memory of given size and return the pointer to |
42 it. */ | |
2720 | 43 void *mc_alloc (size_t size); |
44 | |
3092 | 45 /* Allocate a block of memory as an array with elemcount elements of |
46 given size and return the pointer to it. Arrays contain several | |
47 objects that are allocated in one consecutive block of memory with | |
48 each element being a fully qualified object---that is, it has a | |
49 Lisp object header and a mark bit. Objects like hash tables and | |
50 dynamic arrays use this function. */ | |
51 void *mc_alloc_array (size_t size, EMACS_INT elemcount); | |
52 | |
53 /* Modify the size of the memory block pointed to by ptr. Return the | |
54 address of the new block of given size. The content of the memory | |
55 block will be unchanged to the minimum of the old and new sizes: if | |
56 the new size is smaller, the overlaying data is cut off; if the new | |
57 size is bigger, the newly allocated memory will be uninitialized.*/ | |
2720 | 58 void *mc_realloc (void *ptr, size_t size); |
59 | |
3092 | 60 /* Modify the size of the array pointed to by ptr. Return the address |
61 of the new array block with elemcount elements of given size. The | |
62 content of the memory block will be unchanged to the minimum of the | |
63 old and new sizes: if the new size is smaller, the overlaying data | |
64 is cut off; if the new size is bigger, the newly allocated memory | |
65 will be uninitialized.*/ | |
66 void *mc_realloc_array (void *ptr, size_t size, EMACS_INT elemcount); | |
67 | |
2720 | 68 |
69 | |
70 /* Garbage collection related functions and macros: */ | |
71 | |
3092 | 72 enum mark_bit_colors |
73 { | |
74 WHITE = 0, | |
75 BLACK = 1, | |
76 GREY = 2 | |
77 }; | |
78 | |
79 /* Set the mark bit of the object pointed to by ptr to value.*/ | |
80 void set_mark_bit (void *ptr, EMACS_INT value); | |
81 | |
82 /* Return the mark bit of the object pointed to by ptr. */ | |
83 EMACS_INT get_mark_bit (void *ptr); | |
84 | |
85 /* mark bit macros */ | |
86 /* Returns true if the mark bit of the object pointed to by ptr is set. */ | |
87 #define MARKED_P(ptr) (get_mark_bit (ptr) != WHITE) | |
88 | |
89 /* Marks the object pointed to by ptr (sets the mark bit to 1). */ | |
90 #define MARK(ptr) set_mark_bit (ptr, BLACK) | |
91 | |
92 /* Unmarks the object pointed to by ptr (sets the mark bit to 0). */ | |
93 #define UNMARK(ptr) set_mark_bit (ptr, WHITE) | |
94 | |
95 #define MARK_WHITE(ptr) set_mark_bit (ptr, WHITE) | |
96 #define MARK_GREY(ptr) set_mark_bit (ptr, GREY) | |
97 #define MARK_BLACK(ptr) set_mark_bit (ptr, BLACK) | |
98 | |
99 #define MARKED_WHITE_P(ptr) (get_mark_bit (ptr) == WHITE) | |
100 #define MARKED_GREY_P(ptr) (get_mark_bit (ptr) == GREY) | |
101 #define MARKED_BLACK_P(ptr) (get_mark_bit (ptr) == BLACK) | |
2720 | 102 |
3092 | 103 /* The finalizer of every not marked object is called. The macro |
2720 | 104 MC_ALLOC_CALL_FINALIZER has to be defined and call the finalizer of |
3303 | 105 the object. Returns number of processed pages. */ |
106 EMACS_INT mc_finalize (void); | |
2720 | 107 |
3303 | 108 /* All not marked objects of the used heap are freed. Returns number |
109 of processed pages. */ | |
110 EMACS_INT mc_sweep (void); | |
2720 | 111 |
112 | |
113 | |
114 /* Portable dumper related functions and macros: */ | |
115 | |
116 /* The finalizer for disksave of every object is called to shrink the | |
3092 | 117 dump image. The macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE has to |
3303 | 118 be defined and call the finalizer for disksave of the object. |
119 Returns number of processed pages. */ | |
120 EMACS_INT mc_finalize_for_disksave (void); | |
2720 | 121 |
122 | |
123 | |
124 /* Functions and macros related with allocation statistics: */ | |
125 | |
126 /* Returns the real size, including overhead, which is actually alloced | |
127 for an object with given claimed_size. */ | |
128 Bytecount mc_alloced_storage_size (Bytecount claimed_size, | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
4117
diff
changeset
|
129 struct usage_stats *stats); |
2720 | 130 |
3092 | 131 |
132 /* Incremental Garbage Collector / Write Barrier Support: */ | |
133 | |
134 /* Return the PAGESIZE the allocator uses. Generally equals to the | |
135 system's PAGESIZE. */ | |
136 EMACS_INT mc_get_page_size (void); | |
137 | |
138 /* Is the fault at ptr on a protected page? */ | |
139 EMACS_INT fault_on_protected_page (void *ptr); | |
140 | |
3303 | 141 /* Remove protection (if there) of heap page of given page header ph. |
142 Returns number of processed pages. */ | |
143 EMACS_INT protect_heap_pages (void); | |
3092 | 144 |
3303 | 145 /* Remove protection for all heap pages which are protected. Returns |
146 number of processed pages. */ | |
147 EMACS_INT unprotect_heap_pages (void); | |
3092 | 148 |
149 /* Remove protection and mark page dirty. */ | |
150 void unprotect_page_and_mark_dirty (void *ptr); | |
151 | |
152 /* Repush all objects on dirty pages onto the mark stack. Return | |
153 number of repushed objects. */ | |
154 int repush_all_objects_on_page (void *ptr); | |
155 | |
156 /* Mark black if object is currently grey. */ | |
157 EMACS_INT maybe_mark_black (void *ptr); | |
158 | |
159 /* Only for debugging---not used anywhere in the sources. */ | |
160 EMACS_INT object_on_heap_p (void *ptr); | |
161 | |
2720 | 162 END_C_DECLS |
163 | |
164 #endif /* INCLUDED_mc_alloc_h_ */ |