annotate tests/testincludes/std/gc.d @ 883:b52d5de7783f

GC defines and linkage changes.
author Christian Kamm <kamm incasoftware de>
date Thu, 08 Jan 2009 18:20:02 +0100
parents f7190d9eb70c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
1
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
2 /*
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
3 * Copyright (C) 1999-2006 by Digital Mars, www.digitalmars.com
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
4 * Written by Walter Bright
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
5 *
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
6 * This software is provided 'as-is', without any express or implied
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
7 * warranty. In no event will the authors be held liable for any damages
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
8 * arising from the use of this software.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
9 *
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
10 * Permission is granted to anyone to use this software for any purpose,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
11 * including commercial applications, and to alter it and redistribute it
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
12 * freely, subject to the following restrictions:
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
13 *
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
14 * o The origin of this software must not be misrepresented; you must not
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
15 * claim that you wrote the original software. If you use this software
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
16 * in a product, an acknowledgment in the product documentation would be
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
17 * appreciated but is not required.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
18 * o Altered source versions must be plainly marked as such, and must not
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
19 * be misrepresented as being the original software.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
20 * o This notice may not be removed or altered from any source
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
21 * distribution.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
22 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
23
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
24
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
25 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
26 * The garbage collector normally works behind the scenes without needing any
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
27 * specific interaction. These functions are for advanced applications that
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
28 * benefit from tuning the operation of the collector.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
29 * Macros:
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
30 * WIKI=Phobos/StdGc
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
31 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
32
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
33 module std.gc;
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
34
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
35 import tango.core.Memory;
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
36
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
37 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
38 * Add p to list of roots. Roots are references to memory allocated by the
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
39 collector that are maintained in memory outside the collector pool. The garbage
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
40 collector will by default look for roots in the stacks of each thread, the
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
41 registers, and the default static data segment. If roots are held elsewhere,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
42 use addRoot() or addRange() to tell the collector not to free the memory it
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
43 points to.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
44 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
45 void addRoot(void *p) // add p to list of roots
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
46 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
47 GC.addRoot(p);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
48 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
49
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
50 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
51 * Remove p from list of roots.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
52 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
53 void removeRoot(void *p) // remove p from list of roots
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
54 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
55 GC.removeRoot(p);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
56 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
57
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
58 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
59 * Add range to scan for roots.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
60 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
61 void addRange(void *pbot, void *ptop) // add range to scan for roots
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
62 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
63 GC.addRange(pbot, ptop-pbot);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
64 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
65
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
66 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
67 * Remove range.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
68 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
69 void removeRange(void *pbot) // remove range
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
70 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
71 GC.removeRange(pbot);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
72 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
73
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
74 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
75 * Mark a gc allocated block of memory as possibly containing pointers.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
76 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
77 void hasPointers(void* p)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
78 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
79 GC.clrAttr(p, GC.BlkAttr.NO_SCAN);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
80 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
81
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
82 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
83 * Mark a gc allocated block of memory as definitely NOT containing pointers.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
84 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
85 void hasNoPointers(void* p)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
86 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
87 GC.setAttr(p, GC.BlkAttr.NO_SCAN);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
88 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
89
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
90 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
91 * Mark a gc allocated block of memory pointed to by p as being populated with
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
92 * an array of TypeInfo ti (as many as will fit).
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
93 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
94 //void setTypeInfo(TypeInfo ti, void* p);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
95
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
96 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
97 * Allocate nbytes of uninitialized data.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
98 * The allocated memory will be scanned for pointers during
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
99 * a gc collection cycle, unless
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
100 * it is followed by a call to hasNoPointers().
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
101 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
102 void[] malloc(size_t nbytes)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
103 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
104 void* p = GC.malloc(nbytes);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
105 if (p is null)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
106 return null;
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
107 else
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
108 return p[0..nbytes];
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
109 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
110
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
111 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
112 * Resize allocated memory block pointed to by p to be at least nbytes long.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
113 * It will try to resize the memory block in place.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
114 * If nbytes is 0, the memory block is free'd.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
115 * If p is null, the memory block is allocated using malloc.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
116 * The returned array may not be at the same location as the original
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
117 * memory block.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
118 * The allocated memory will be scanned for pointers during
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
119 * a gc collection cycle, unless
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
120 * it is followed by a call to hasNoPointers().
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
121 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
122 void[] realloc(void* p, size_t nbytes)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
123 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
124 p = GC.realloc(p, nbytes);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
125 if (p is null)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
126 return null;
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
127 else
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
128 return p[0..nbytes];
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
129 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
130
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
131 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
132 * Attempt to enlarge the memory block pointed to by p
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
133 * by at least minbytes beyond its current capacity,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
134 * up to a maximum of maxbytes.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
135 * Returns:
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
136 * 0 if could not extend p,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
137 * total size of entire memory block if successful.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
138 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
139 size_t extend(void* p, size_t minbytes, size_t maxbytes)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
140 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
141 return GC.extend(p, maxbytes, minbytes);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
142 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
143
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
144 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
145 * Returns capacity (size of the memory block) that p
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
146 * points to the beginning of.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
147 * If p does not point into the gc memory pool, or does
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
148 * not point to the beginning of an allocated memory block,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
149 * 0 is returned.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
150 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
151 size_t capacity(void* p)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
152 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
153 return GC.sizeOf(p);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
154 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
155
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
156 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
157 * Set gc behavior to match that of 1.0.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
158 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
159 void setV1_0()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
160 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
161 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
162
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
163 /***********************************
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
164 * Run a full garbage collection cycle.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
165 *
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
166 * The collector normally runs synchronously with a storage allocation request
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
167 (i.e. it never happens when in code that does not allocate memory). In some
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
168 circumstances, for example when a particular task is finished, it is convenient
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
169 to explicitly run the collector and free up all memory used by that task. It
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
170 can also be helpful to run a collection before starting a new task that would
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
171 be annoying if it ran a collection in the middle of that task. Explicitly
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
172 running a collection can also be done in a separate very low priority thread,
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
173 so that if the program is idly waiting for input, memory can be cleaned up.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
174 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
175
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
176 void fullCollect()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
177 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
178 GC.collect();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
179 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
180
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
181 /***********************************
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
182 * Run a generational garbage collection cycle.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
183 * Takes less time than a fullcollect(), but isn't
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
184 * as effective.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
185 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
186
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
187 void genCollect()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
188 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
189 GC.collect();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
190 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
191
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
192 //void genCollectNoStack();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
193
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
194 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
195 * Minimizes physical memory usage
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
196 */
333
f7190d9eb70c [svn r354] Fix the regressions between [346] and [353] by making constructors and destructors outside classes fatal errors.
ChristianK
parents: 326
diff changeset
197 void minimize()
f7190d9eb70c [svn r354] Fix the regressions between [346] and [353] by making constructors and destructors outside classes fatal errors.
ChristianK
parents: 326
diff changeset
198 {
f7190d9eb70c [svn r354] Fix the regressions between [346] and [353] by making constructors and destructors outside classes fatal errors.
ChristianK
parents: 326
diff changeset
199 GC.collect();
f7190d9eb70c [svn r354] Fix the regressions between [346] and [353] by making constructors and destructors outside classes fatal errors.
ChristianK
parents: 326
diff changeset
200 }
326
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
201
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
202 /***************************************
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
203 * disable() temporarily disables garbage collection cycle, enable()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
204 * then reenables them.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
205 *
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
206 * This is used for brief time critical sections of code, so the amount of time
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
207 * it will take is predictable.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
208 * If the collector runs out of memory while it is disabled, it will throw an
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
209 * std.outofmemory.OutOfMemoryException.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
210 * The disable() function calls can be nested, but must be
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
211 * matched with corresponding enable() calls.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
212 * By default collections are enabled.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
213 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
214
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
215 void disable()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
216 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
217 GC.disable();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
218 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
219
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
220 /**
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
221 * ditto
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
222 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
223 void enable()
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
224 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
225 GC.enable();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
226 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
227
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
228 //void getStats(out GCStats stats);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
229
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
230 /***************************************
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
231 * Get handle to the collector.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
232 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
233
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
234 //void* getGCHandle();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
235
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
236 /***************************************
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
237 * Set handle to the collector.
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
238 */
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
239
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
240 //void setGCHandle(void* p);
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
241
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
242 //void endGCHandle();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
243
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
244 /*
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
245 extern (C)
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
246 {
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
247 void gc_init();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
248 void gc_term();
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
249 }
d7e42b5d8ccd [svn r347] Foundation for adding tangobos to test environment is in place.
ChristianK
parents:
diff changeset
250 */