I'm trying to optimize memory access to an SDL_Surface in the lispbuilder-sdl project. An SDL_Surface is basically a foreign array. Reading and writing individual pixels involves calling MEM-AREF to access an integer value at a specific offset in the SDL_Surface array. This is fine for individual pixel reads and writes but sub-optimal for a rotation function where there is a read and corresponding write for each pixel in the surface (For example a 320x240 resolution surface requires a total of 153,600 calls to MEM-AREF in order to perform a rotation.)
Can I use WITH-POINTER-TO-VECTOR-DATA to somehow speed this up?
Thanks, - Luke
Luke Crook wrote:
An SDL_Surface is basically a foreign array. Reading and writing individual pixels involves calling MEM-AREF to access an integer value ... Can I use WITH-POINTER-TO-VECTOR-DATA to somehow speed this up?
Nope, WITH-POINTER-TO-VECTOR-DATA is not the right abstraction for this. As you said, you have a foreign array. Alas, CL does not allow to portably extend the built-in ARRAY type. Your best bet is to look at CFFI's proposed block transfer operations, which ought to be optimised for speed. http://cffi.common-lisp.net/project/cffi/darcs/cffi/doc/mem-vector.txt
Outside of CFFI's scope, you may find that some implementations provide for means to have specialised Lisp arrays mapped at known (malloc'ed) locations. I believe Allegro features this. Then you can use all of CL's array and sequence functions on the foreign memory area.
Regards, Jorg Hohle.