This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Jim Blandy <jimb@red-bean.com> writes: > > I would also find it very useful if there were a way to get guile to > > treat a region of memory as a uniform array (and not try to GC the > > memory block). This would let me attach to large chunks of memory > > allocated by other packages. > > Should Guile call a hook associated with the array to free its space? I think that would play hob with the whole idea of shared arrays, which are, IMO, quite useful. Currently, an array is a smob whose cdr points to something like: { SCM vector; size_t base; /* dimensions */ size_t lower_bound; size_t upper_bound; size_t increment; ... } The number of dimensions is encoded in the upper bits of the car of the array. It might be reasonable to encode some vector type information in the car of the array as well, using perhaps 8 bits. There need not be a further restriction on number of dimensions if arrays were made a scm_tc7_ type, several of which could be freed up by demoting some of the uniform vector types to uniform array subtypes. The cdr of the array would then look like: { SCM gc_protect; /* typically a vector or uniform vector */ void *ptr; /* dimensions */ size_t lower_bound; size_t upper_bound; size_t increment; ... } `ptr' would point to the beginning of the array elements, if those array elements were part of a uniform vector then that vector would be pointed to by `gc_protects'. Since the array would contain both type information and a pointer to array elements, no other use of the uniform vector would be necessary. This should make array-ref marginally faster for arrays, and, if carefully done, no slower for uniform vectors. If the array had a type not corresponding to a uniform vector type, then some sort of gc_protect object would have to be created to eventually free the element vector, perhaps by calling a user-supplied hook. If the array elements were not free-able from Guile, then gc_protect would be an immediate. It might be useful to dynamically add array types, ala smobs. Each type would be associated with at least `maker', `getter', and `setter' functions, and the size of a single element.