Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: trouble with C pointers and GC
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: doligez@p...
Subject: Re: trouble with C pointers and GC

>From: Patrick Goldbronn - SYSCO <patrick.goldbronn@cea.fr>

>  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)".

-- Damien