* trouble with C pointers and GC @ 1999-04-19 14:42 ` Patrick Goldbronn - SYSCO 1999-04-19 18:50 ` doligez 0 siblings, 1 reply; 2+ messages in thread From: Patrick Goldbronn - SYSCO @ 1999-04-19 14:42 UTC (permalink / raw) To: caml-list Hello, I have some trouble to return a structure with pointers outside the heap ! I allocate two C pointer : 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 ) ; I don't know what is the value of n (n words) : A pointer value represent 1 word or 2 ? How can I store the pointers adr1 and adr2 in value result and how can I retrieve them (with Store_field and Field ?) ? Thank you for your assistance. -- ###################### # Patrick GOLDBRONN # # CEA- DRN/DMT/SYSCO # ###################### ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: trouble with C pointers and GC 1999-04-19 14:42 ` trouble with C pointers and GC Patrick Goldbronn - SYSCO @ 1999-04-19 18:50 ` doligez 0 siblings, 0 replies; 2+ messages in thread From: doligez @ 1999-04-19 18:50 UTC (permalink / raw) To: caml-list >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 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-04-20 6:32 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <patrick.goldbronn@cea.fr> 1999-04-19 14:42 ` trouble with C pointers and GC Patrick Goldbronn - SYSCO 1999-04-19 18:50 ` doligez
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox