From: <wa...@te...> - 2009-09-11 15:37:10
|
Excellent, that solves that problem, thanks, I spent an hour puzzling over it befire retiring for the night.<br/><br/>Unfortunately, I have to use make-alien because of the larger problem I'm solving, basically writing a file-system. I've made a lisp 'page-manager', similar to an OS or database one. I use make-alien because I need a large permanent space. Lisp was a good fit for this, because it make writing the page-acquire, page-write, page-read, page-lock, etc methods easy.<br/><br/>The trouble is, Lisp isn't good at imposing structure onto a block of memory, and C is good for nothing else. So what I'm doing is defining my on disk formats as C-structures, and writing C-routines to do the fine manipulation, while lisp does the overall planning. For example, in my B+Tree implementation, Lisp decides where to go, and C reads whats there.<br/><br/>I'm open to other suggestions, because I do like all-lisp solutions. I've already tried the Practical Common Lisp method (using a macro to build CLOS classes /w a read-binary method), and I've tried building a complex-macro that turns structure definitions into array+offset accessors. The former fails because I am randomly reading/writing an array of data, not streaming. The latter works but is longer than the C code, and harder to read.<br/><br/>Cheers,<br/>Warren Wilkinson<br/><br/><br/>Sep 11, 2009 05:26:02 AM, nik...@ra... wrote:<br/><br/>===========================================<br/><br/>2009/9/11 wa...@te...>:<br/><br/>> Am I using this thing right? I would think that anything dynamically<br/>> allocated memory should be passed into C in just this way, but SBCL (1.0.29<br/>> on Gentoo) disagrees.<br/><br/>The Lisp side is fine, it's your C code that is in error:<br/><br/>> if (data = NULL) {<br/>> return EINVAL;<br/>> }<br/><br/>You want data == NULL, not data = NULL... :)<br/><br/>(Though you probably want to use WITH-ALIEN instead of MAKE-ALIEN &<br/>FREE-ALIEN, but that's a style-issue.)<br/><br/>Cheers,<br/><br/> -- Nikodemus<br/> |