Subject: Re: trouble with C pointers and GC
In-Reply-To: Message of Mon, 19 Apr 1999 16:42:30 +0200
from Patrick Goldbronn - SYSCO <email@example.com>
Date: Mon, 19 Apr 1999 11:50:19 -0700
>From: Patrick Goldbronn - SYSCO <firstname.lastname@example.org>
> adr1 = (double *) calloc(nb1,sizeof(double));
> adr2 = (int *) calloc(nb2,sizeof(int));
>and I want to put it in a value with Final_tag :
> result = alloc_final( n , free_function , nb_elm*2 , 1 ) ;
This doesn't look right: it will force a major GC every time, unless
nb_elm == 0.
>I don't know what is the value of n (n words) : A pointer value
>represent 1 word or 2 ?
A pointer is 1 word, and you must count the pointer to free_function,
so n would be 3.
>How can I store the pointers adr1 and adr2 in value result and how can I
>retrieve them (with Store_field and Field ?) ?
Since the pointer to free_function uses the first field, they would be
at offsets 1 and 2:
result = alloc_final (3, &free_function, 0, 1);
Store_field (result, 1, adr1);
Store_field (result, 2, adr2);
And to use them: "Field (result, 1)" and "Field (result, 2)".
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:22 MET