Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

root/tags/releases/0.99.8/lib/gc/stub/gc.d

Revision 3880, 2.8 kB (checked in by sean, 2 years ago)

Brought stub GC up to date.

  • Property svn:eol-style set to native
Line 
1 /**
2  * This module contains a minimal garbage collector implementation according to
3  * Tango requirements.  This library is mostly intended to serve as an example,
4  * but it is usable in applications which do not rely on a garbage collector
5  * to clean up memory (ie. when dynamic array resizing is not used, and all
6  * memory allocated with 'new' is freed deterministically with 'delete').
7  *
8  * Please note that block attribute data must be tracked, or at a minimum, the
9  * FINALIZE bit must be tracked for any allocated memory block because calling
10  * rt_finalize on a non-object block can result in an access violation.  In the
11  * allocator below, this tracking is done via a leading uint bitmask.  A real
12  * allocator may do better to store this data separately, similar to the basic
13  * GC normally used by Tango.
14  *
15  * Copyright: Public Domain
16  * License:   Public Domain
17  * Authors:   Sean Kelly
18  */
19
20 private import tango.stdc.stdlib;
21
22 private
23 {
24    enum BlkAttr : uint
25     {
26         FINALIZE = 0b0000_0001,
27         NO_SCAN  = 0b0000_0010,
28         NO_MOVE  = 0b0000_0100,
29         ALL_BITS = 0b1111_1111
30     }
31
32     struct BlkInfo
33     {
34         void*  base;
35         size_t size;
36         uint   attr;
37     }
38
39     extern (C) void thread_init();
40     extern (C) void onOutOfMemoryError();
41 }
42
43 extern (C) void gc_init()
44 {
45     // NOTE: The GC must initialize the thread library before its first
46     //       collection, and always before returning from gc_init().
47     thread_init();
48 }
49
50 extern (C) void gc_term()
51 {
52
53 }
54
55 extern (C) void gc_enable()
56 {
57
58 }
59
60 extern (C) void gc_disable()
61 {
62
63 }
64
65 extern (C) void gc_collect()
66 {
67
68 }
69
70 extern (C) void gc_minimize()
71 {
72
73 }
74
75 extern (C) uint gc_getAttr( void* p )
76 {
77     return 0;
78 }
79
80 extern (C) uint gc_setAttr( void* p, uint a )
81 {
82     return 0;
83 }
84
85 extern (C) uint gc_clrAttr( void* p, uint a )
86 {
87     return 0;
88 }
89
90 extern (C) void* gc_malloc( size_t sz, uint ba = 0 )
91 {
92     void* p = malloc( sz );
93
94     if( sz && p is null )
95         onOutOfMemoryError();
96     return p;
97 }
98
99 extern (C) void* gc_calloc( size_t sz, uint ba = 0 )
100 {
101     void* p = calloc( 1, sz );
102
103     if( sz && p is null )
104         onOutOfMemoryError();
105     return p;
106 }
107
108 extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 )
109 {
110     p = realloc( p, sz );
111
112     if( sz && p is null )
113         onOutOfMemoryError();
114     return p;
115 }
116
117 extern (C) size_t gc_extend( void* p, size_t mx, size_t sz )
118 {
119     return 0;
120 }
121
122 extern (C) size_t gc_reserve( size_t sz )
123 {
124     return 0;
125 }
126
127 extern (C) void gc_free( void* p )
128 {
129     free( p );
130 }
131
132 extern (C) void* gc_addrOf( void* p )
133 {
134     return null;
135 }
136
137 extern (C) size_t gc_sizeOf( void* p )
138 {
139     return 0;
140 }
141
142 extern (C) BlkInfo gc_query( void* p )
143 {
144     return BlkInfo.init;
145 }
146
147 extern (C) void gc_addRoot( void* p )
148 {
149
150 }
151
152 extern (C) void gc_addRange( void* p, size_t sz )
153 {
154
155 }
156
157 extern (C) void gc_removeRoot( void *p )
158 {
159
160 }
161
162 extern (C) void gc_removeRange( void *p )
163 {
164
165 }
Note: See TracBrowser for help on using the browser.