Thomas Chust <[email protected]> writes: > > Hello John, > > looking at your code I have two immediate questions: Why do you > recompute the length of a list twice, which is a linear operation, > when you could simply store the length or access the length of the > vector you create in constant time? >
Just sloppiness, while I try to get things working. >> I malloc memory and copy the data into the block, then return the >> pointer to the block for use in scheme. > > And why do you allocate this block at all when you already have a > u32vector with precisely the same memory layout? > On a 64 bit machine, an unsigned long will be 64 bits, and this is what xlib expects. >> My question is, what is the idiomatic way in Chicken to free the >> allocated memory, or turn it over to the garbage collector? >> [...] > > If you really need this block of unmanaged memory for some obscure > reason, you can either manually free it at some point where it is safe > to do so, or you can register the free function as a finalizer on the > foreign pointer object and let the garbage collector invoke it after > the pointer has gone out of scope from the viewpoint of your CHICKEN > program. Something like this should do: > > (set-finalizer! YOUR-POINTER (foreign-lambda void "free" c-pointer)) > > Ciao, > Thomas Very nice, thank you. -- John Foerch _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
