From: Gabriel D. R. <gd...@in...> - 2008-10-27 04:07:55
|
On Sun, Oct 26, 2008 at 10:08 PM, Sam Steingold <sd...@gn...> wrote: >> * Gabriel Dos Reis <tq...@va...g> [2008-10-26 16:31:32 -0500]: >> >> What is the API to get hold on the `pointer to data' of the vector? >> (In SBCL, I can use vector-sap). > > there is no API for that, and I don't think you need it. > all you need to do is define your foreign function to accept a vector > argument an then pass in the vector object. > at this time however the lisp vector will be copied into a temporary > memory area which will be passed to the C function (with the obvious > performance implications). Yes; however, I suspect there must be an API to specifically ask for the pointer to data being passed as opposed to the copy which is performance killer. At least, if one wants to maintain both semantics. > anything else would be unsafe. > > Joerg, what do you think about adding an argument flag to pass the array > data pointer instead of the temporary memory area? > to ensure safety, such an ffi argument would translate into 2 C > arguments: pointer and size in bytes. > i.e.: > > (def-call-out foo (:arguments (x lisp-data)) ...) > > would correspond to > > foo (void *x, size_t len) > > of course, this would open a Pandora's box wrt possible crashes and > memory corruption, but I think we already have that: Yes. However, I do believe the above -- while useful for many cases -- is too coarse. For example, I may want to specify the argument to the foreign function in specific order, not necessarily the order shown above. Also, there are cases where I would like to specify an amount actually less than the real length of the vector (e.g. taking a sub-vector, or a slice). [...] >>> note however that clisp does not have arrays specialized to floats. >>> (yet). >> >> So, a vector of float is the same as a vector of any type (except >> vector of byte)? > > (vector float) == (vector t) > > CLISP specializes arrays for bits, chars, ([un]signed-byte n) for > n=1,2,4,8,16,32. OK; thanks. > > >> Would the specializations for vector of float, vector of double, and >> vector of fixnum disrupt CLisp design? Is it something possible for > > (vector fixnum)? > you mean (vector (unsigned-byte 24)) on 32-bit platforms and (vector > (unsigned-byte 48))on 64-bit platforms? > why do you need them? If the specialization is already there for 32-bit integer vectors then I don't need specialization for vector of fixnums. > >> the forseable future? > > http://www.cygwin.com/acronyms/#PTC > > we have 4 bits (arrayflags_atype_mask in clisp/src/lispbibl.d) for array > storage vector type and only 9 atypes are used at this time, so we > should be able to add Atype_64Bit, Atype_float and Atype_double. -- Gaby |