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').
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.
15 * Copyright: Public Domain
17 * Authors: Leandro Lucarella
26 FINALIZE = 0b0000_0001,
27 NO_SCAN = 0b0000_0010,
28 NO_MOVE = 0b0000_0100,
29 ALL_BITS = 0b1111_1111,
41 BlkAttr attr = cast(BlkAttr) 0;
45 static Cell* from_ptr(void* ptr)
49 return cast(Cell*) (cast(byte*) ptr - Cell.sizeof);
54 return cast(void*) (cast(byte*) this + Cell.sizeof);
59 return cast(bool) (this.attr & BlkAttr.FINALIZE);
64 return !(this.attr & BlkAttr.NO_SCAN);
67 int opApply(int delegate(ref void*) dg)
70 auto from = cast(void**) this.ptr;
71 auto to = cast(void**) this.ptr + this.size;
72 // TODO: alignment. The range should be aligned and the size
73 // should be a multiple of the word size. If the later does
74 // not hold, the last bytes that are not enough to build
75 // a complete word should be ignored. Right now we are
76 // doing invalid reads in that cases.
77 for (auto current = from; current < to; current++) {
78 result = dg(*current);
87 // vim: set et sw=4 sts=4 :