chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] using mmap files as strings?


From: Jim Ursetto
Subject: Re: [Chicken-users] using mmap files as strings?
Date: Sat, 23 Oct 2010 20:11:20 -0500

On Sat, Oct 23, 2010 at 05:04, Peter Bex <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]