I've started learning Lisp recently and wanted to write a program which uses gtk interface. I've installed lambda-gtk bindings (on CMUCL). I want to have putpixel/getpixel ability on a pixbuf. But I found that I'm unable to direct access memory. (or just don't know how)
Function (gdk:pixbuf-get-pixels pixbuf) returns me a number - memory addr, I guess. In C++ I can easily get to the pixel I need. Is there any way to write my own putpixel in Lisp?
Several functions for manipulating a fill pointer are provided in Common Lisp to make it easy to incrementally fill in the contents of a vector and, more generally, to allow efficient varying of the length of a vector.
A Lisp object is a collection of consecutive memory cells. Each cell is large enough to hold the address of any Lisp object; this stored address is called a pointer. For example, a cons consists of two memory cells, one for the car and one for the cdr.
In Lisp, modern and portable way to access C libraries and to do direct memory access is CFFI.
You can use it like this:
>(defparameter *p* (cffi:foreign-alloc :unsigned-char :count 10))
;; allocate 10 bytes
*P*
> (setf (cffi:mem-aref *p* :unsigned-char 0) 10)
;; access *p* as an array of bytes and set its 0th element to 10
10
> (cffi:mem-aref *p* :unsigned-char 0)
;; access *p* as an array of bytes and take its 0th element
10
> (cffi:make-pointer 123)
;; make a pointer that points to given address
#.(SB-SYS:INT-SAP #X0000007B)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With