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: Alan Post
Subject: Re: [Chicken-users] using mmap files as strings?
Date: Fri, 22 Oct 2010 17:58:02 -0600

On Fri, Oct 22, 2010 at 06:20:01AM -0400, Felix wrote:
> From: Alan Post <address@hidden>
> Subject: [Chicken-users] using mmap files as strings?
> Date: Thu, 21 Oct 2010 15:01:10 -0600
> 
> > I have the following file:
> > 
> > <++> mmap.scm
> > (use posix)
> > (use 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)))
> >   (write fd)
> >   (newline)
> >   (write size)
> >   (newline)
> >   (write mmap)
> >   (newline)
> >   (write buf)
> >   (newline)
> >   (write (pointer-s8-ref buf))
> >   (newline)
> >   (write (integer->char (pointer-s8-ref buf)))
> >   (newline))
> > <-->
> > 
> > Which opens itself as an mmap and reads the first byte.  The output
> > is:
> > 
> > <++> csc -o mmap mmap.scm && ./mmap
> > 3
> > 458
> > #<mmap>
> > #<pointer 0x8818c000>
> > 40
> > #\(
> > <-->
> > 
> > So far so good, that is what I would expect.  I'd like to work with
> > an mmap buffer like a string.  Is it possible to create an object
> > that will treat the mmap area as a string that I can run regular
> > string operations on without copying the mmap buffer? 
> 
> I can't think of a way in the moment. Strings require a header-word,
> and the data pointed to by a pointer doesn't have that header, so it
> isn't possible to "sneak in" a pointer as a replacement of a string.
> 
> > I'm
> > specifically interested in running regular expressions across the
> > mmap space.
> 
> irregex provides a "chunk" based API, perhaps it is possible to
> define chunks over the data represented by the mmap pointer.
> Alex or Peter might be able to tell more about this.
> 

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?

I think I can accomplish what I have in mind by thunking to C,
though in that case I'd need to create scheme strings of the
results.

Thank you!

-Alan
-- 
.i ko djuno fi le do sevzi



reply via email to

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