BlitzMax Extended
0.8.18
Pushing Blitz to the Max.
Main Page
Related Pages
Data Structures
Files
File List
Globals
c
blitz_gc.h
Go to the documentation of this file.
1
23
#ifndef BLITZ_GC_H
24
#define BLITZ_GC_H
25
26
#include "_common.h"
27
28
BB_BEGIN_DECLS
29
30
#ifdef BB_THREADED
31
# include "
blitz_thread.h
"
32
# ifndef BB_GC_MS
33
# define BB_GC_MS
34
# endif
35
#else
36
# ifndef BB_GC_RC
37
# define BB_GC_RC
38
# endif
39
#endif
40
41
#define BBGC_MANYREFS 0x40000000
42
43
// Probably shouldn't be here...
44
#if __ppc__
45
# define BBGC_NUM_ROOTREGS 19
46
#else
47
# define BBGC_NUM_ROOTREGS 4
48
#endif // __ppc__
49
50
void
* bbGCRootRegs(
void
*ptr);
51
void
bbGCStartup();
52
57
enum
BBGCMode
58
{
65
BBGC_AUTOMATIC
= 1,
66
74
BBGC_MANUAL
= 2,
75
76
BBGC_AGGRESSIVE = -1
77
};
78
79
typedef
enum
BBGCMode
BBGCMode
;
80
81
#define BBGC_MODE_ISVALID(mode) \
82
( \
83
(mode) == BBGC_AUTOMATIC || \
84
(mode) == BBGC_MANUAL || \
85
(mode) == BBGC_AGGRESSIVE \
86
)
87
93
BBGCMode
bbGCGetMode
();
94
101
void
bbGCSetMode
(
BBGCMode
mode);
102
107
enum
BBGCDebugMode
108
{
113
BBGC_NODEBUG
,
114
116
BBGC_STDOUTDEBUG
117
};
118
119
typedef
enum
BBGCDebugMode
BBGCDebugMode
;
120
127
void
bbGCSetDebug
(
BBGCDebugMode
mode);
128
134
enum
BBGCAllocFlags
135
{
139
BBGC_DEFAULT,
140
145
BBGC_ATOMIC
,
146
151
BBGC_FINALIZE
152
};
153
154
typedef
enum
BBGCAllocFlags
BBGCAllocFlags
;
155
162
void
*
bbGCMalloc
(
BBInt
size,
BBInt
flags);
163
174
BBObject
* bbGCAllocObject(BBSize size,
const
BBClass
*clas,
BBInt
flags);
175
181
BBBool
bbGCValidate
(
const
void
*ptr);
182
187
BBInt
bbGCMemAlloced
();
188
197
BBInt
bbGCCollect
();
198
204
#define BBGC_MAX_SUSPENDED (BBINT_MAX - 1)
205
221
void
bbGCSuspend
();
222
230
BBBool
bbGCIsSuspended
();
231
241
void
bbGCResume
();
242
246
void
bbGCRetain(
BBObject
*obj);
247
251
void
bbGCRelease(
BBObject
*obj);
252
253
// BB_RETAIN/BB_RELEASE should be used to prevent an object from garbage collection.
254
//
255
// This is mainly of use if an object is being stored outside of BlitzMax's 'sight' - say, in a C++ table.
256
// You can also use bbGCRetain/bbGCRelease functions above if necessary - MACROS are just faster.
257
258
#ifdef BB_GC_RC
259
# define BB_RETAIN(obj) { ++(obj)->refs; }
260
# define BB_RELEASE(obj) { if (!--(obj)->refs) { bbGCFree(obj); } }
261
#else
262
# define BB_RETAIN(obj) bbGCRetain(((BBObject *)(obj)));
263
# define BB_RELEASE(obj) bbGCRelease(((BBObject *)(obj)));
264
#endif
265
266
// Internal use only
267
#ifdef BB_GC_RC
268
269
/*
270
* Called when there are no more references (obj->refs == 0)
271
*
272
* \param obj The object to free
273
*/
274
void
bbGCFree(
BBObject
*obj);
275
276
/*
277
* Called after the destructor to send the memory to nirvana.
278
*
279
* \param obj The object to deallocate
280
* \param size The size of the object instance
281
*/
282
void
bbGCDeallocObject(
BBObject
*obj, BBSize size);
283
284
# define BB_INCREFS(obj) { ++(obj)->refs; }
285
# define BB_DECREFS(obj) { if (!--(obj)->refs) { bbGCFree(obj); } }
286
#else
287
# define BB_INCREFS(obj) {}
288
# define BB_DECREFS(obj) {}
289
#endif
290
291
// DEPERECATED
292
293
#ifndef BB_DISABLE_DEPRECATED
294
295
# ifdef BB_GC_RC
296
# define BBINCREFS(obj) { ++(obj)->refs; }
297
# define BBDECREFS(obj) { if (!--(obj)->refs) { bbGCFree(obj); } }
298
# define BBRETAIN(obj) { ++(obj)->refs; }
299
# define BBRELEASE(obj) { if (!--(obj)->refs) { bbGCFree(obj); } }
300
# else
301
# define BBINCREFS(obj) {}
302
# define BBDECREFS(obj) {}
303
# define BB_RETAIN(obj) bbGCRetain(((BBObject *)(obj)));
304
# define BB_RELEASE(obj) bbGCRelease(((BBObject *)(obj)));
305
# endif // !BB_GC_RC
306
307
#endif // !BB_DISABLE_DEPRECATED
308
309
BB_END_DECLS
310
311
#endif // BLITZ_GC_H
Generated on Wed Oct 10 2012 19:14:23 for BlitzMax Extended by
1.8.1.1