On Sat, Oct 23, 2010 at 05:04, Peter Bex <peter....@xs4all.nl> wrote:
> On Fri, Oct 22, 2010 at 05:58:02PM -0600, Alan Post wrote:
>> This is excellent, I've learned a lot more about how all of this
>> works together now.
>>
>> What method would I use to convert a pointer and a length to a
>> string?  Even though I'm copying the memory, how do I do it at
>> all?
>
> Something like this:
>
> {
>  C_word *scheme_string;
>
>  scheme_string = C_alloc(C_SIZEOF_STRING(the_length));
>  C_string(&scheme_string, the_length, the_pointer);
>  C_kontinue(the_continuation, scheme_string);
> }

I think this might be better:

(let ((to (make-string len))
 (move-memory! from to len))

Using your original example,

(use posix lolevel)

(let* ((fd (file-open "mmap.scm" (+ open/rdonly open/nonblock)))
       (size (file-size fd))
       (mmap (map-file-to-memory #f size prot/read (+ map/file map/shared) fd))
       (buf  (memory-mapped-file-pointer mmap)))
  (let* ((len 10)
          (str (make-string len)))
    (move-memory! buf str len)
    (print str)))

$ csi -script mmap.scm
(use posix

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to