Thread overview
Allocating from the GC
Sep 07, 2003
Ben Hinkle
Sep 08, 2003
Ben Hinkle
Sep 08, 2003
Mike Wynn
Sep 09, 2003
Ben Hinkle
September 07, 2003
I notice gc.d doesn't have malloc, realloc or free. The file gcx.d does. But
gcx isn't on the toplevel phobos path and that makes me think it isn't
supposed to be called.
How do I allocate memory from the GC pool myself? Should I go through gcx?
When I try to include it in my path I get the error

/home/bhinkle/dmd/src/phobos/gc2/gcx.d(631): function expected before (),
not 'module memset'

I want to pass the GC allocation routines to a C library (that gmp thing again) so that it can allocate from GC memory instead of C's malloc etc.

thanks,
-Ben


September 08, 2003
"Ben Hinkle" <bhinkle4@juno.com> wrote in message news:bjgacv$16hg$1@digitaldaemon.com...
> I notice gc.d doesn't have malloc, realloc or free. The file gcx.d does.
But
> gcx isn't on the toplevel phobos path and that makes me think it isn't
> supposed to be called.
> How do I allocate memory from the GC pool myself? Should I go through gcx?
> When I try to include it in my path I get the error
>
> /home/bhinkle/dmd/src/phobos/gc2/gcx.d(631): function expected before (),
> not 'module memset'

whoops - this error was my fault. I was trying to import memset. When I take
that out I still can't seem to get the right api.
Now I'm trying to modify src/phobos/gc.d to include malloc, realloc and
free.

> I want to pass the GC allocation routines to a C library (that gmp thing again) so that it can allocate from GC memory instead of C's malloc etc.
>
> thanks,
> -Ben
>
>


September 08, 2003
Ben Hinkle wrote:
> I notice gc.d doesn't have malloc, realloc or free. The file gcx.d does. But
> gcx isn't on the toplevel phobos path and that makes me think it isn't
> supposed to be called.
> How do I allocate memory from the GC pool myself? Should I go through gcx?
> When I try to include it in my path I get the error
> 
> /home/bhinkle/dmd/src/phobos/gc2/gcx.d(631): function expected before (),
> not 'module memset'
> 
> I want to pass the GC allocation routines to a C library (that gmp thing
> again) so that it can allocate from GC memory instead of C's malloc etc.
> 
> thanks,
> -Ben
> 
> 
what about `&((new ubyte[len])[0])` ??


September 09, 2003
> what about `&((new ubyte[len])[0])` ??

thanks! that works great.

Now I just have to figure out how to get the GC to work in linux. It seems to seg fault whenever I run fullCollect or genCollect and if I let it burn memory it never collects itself. :P

Here's a sample program to test the gc

import gc;
int main(char[][] args) {
    ubyte[] foo;
    GCStats stats;
    char *fmt = "%u %u %u %u\n";
    while (true) {
        foo = new ubyte[10];
        getStats(stats);
        printf(fmt,stats.poolsize,
               stats.usedsize,
               stats.freeblocks,
               stats.freelistsize);
    }
    return 0;
}

and here is the output

65536 128 14 8064
65536 144 14 8048
65536 160 14 8032
[snip]
1048576 1048528 0 48
1048576 1048544 0 32
1048576 1048560 0 16
1048576 1048576 0 0
Segmentation fault