Map list of strings into memory
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Lukáš Zapletal <luka... @zapletalovi.com>
Date: Mon, 5 Nov 2012 13:56:58 -0800 (PST)
Local: Mon, Nov 5 2012 4:56 pm
Subject: Map list of strings into memory
Hello,
I would like to map file created with
find / >the_file
(text file, each line one entry) into memory with golang and then iterate through it. For memory mapping there is
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error)
which returns byte slice, now, to read a line I plan to reach byte by byte. Is there more effective approach?
Is there something if I would replace newlines in the file with zero bytes?
Thanks
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Peter S <speter.... @gmail.com>
Date: Tue, 6 Nov 2012 12:43:54 +0900
Local: Mon, Nov 5 2012 10:43 pm
Subject: Re: [go-nuts] Map list of strings into memory
If you don't insist on using Go and mmap to achieve your goal, you might
want to try:
find / -print0 > the_file
It also has the advantage of working correctly when some file names contain
newline characters.
Peter
On Tue, Nov 6, 2012 at 6:56 AM, Lukáš Zapletal <luka... @zapletalovi.com>wrote:
> Hello,
> I would like to map file created with
> find / >the_file
> (text file, each line one entry) into memory with golang and then iterate
> through it. For memory mapping there is
> func Mmap(fd int, offset int64, length int, prot int, flags int) (data
> []byte, err error)
> which returns byte slice, now, to read a line I plan to reach byte by
> byte. Is there more effective approach?
> Is there something if I would replace newlines in the file with zero bytes?
> Thanks
> --
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Miguel Pignatelli <eme... @gmail.com>
Date: Tue, 06 Nov 2012 10:03:39 +0000
Local: Tues, Nov 6 2012 5:03 am
Subject: Re: [go-nuts] Map list of strings into memory
On 05/11/12 21:56, Luk Zapletal wrote:
> Hello,
> I would like to map file created with
> find / >the_file
> (text file, each line one entry) into memory with golang and then
> iterate through it. For memory mapping there is
> func Mmap(fd int, offset int64, length int, prot int, flags int) (data
> []byte, err error)
> which returns byte slice, now, to read a line I plan to reach byte by
> byte. Is there more effective approach?
> Is there something if I would replace newlines in the file with zero bytes?
> Thanks
> --
Why don't you use ioutil/ReadFile?
Or just open the file with and read line by line with bufio/ReadLine?
M;
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Larry Clapp <la... @theclapp.org>
Date: Tue, 6 Nov 2012 06:59:55 -0800 (PST)
Local: Tues, Nov 6 2012 9:59 am
Subject: Re: Map list of strings into memory
Just to make sure: You know you could either just pipe find into your Go program:
find / | your_go_program
or open a pipe from find in your Go program (http://golang.org/pkg/os/#Pipe ) directly, right?
No mmap required.
To answer your question, in the buffer package there are functions that allow you to read directly from the buffer using regular Read calls.
As for newlines -> zero bytes: find -print0. See also the find manpage for other printing options, e.g. -printf or -fprintf or -fprint0.
-- L
On Monday, November 5, 2012 4:56:58 PM UTC-5, Lukáš Zapletal wrote:
> Hello,
> I would like to map file created with
> find / >the_file
> (text file, each line one entry) into memory with golang and then iterate > through it. For memory mapping there is
> func Mmap(fd int, offset int64, length int, prot int, flags int) (data > []byte, err error)
> which returns byte slice, now, to read a line I plan to reach byte by > byte. Is there more effective approach?
> Is there something if I would replace newlines in the file with zero bytes?
> Thanks
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Larry Clapp <la... @theclapp.org>
Date: Tue, 6 Nov 2012 07:19:23 -0800 (PST)
Local: Tues, Nov 6 2012 10:19 am
Subject: Re: Map list of strings into memory
On Tuesday, November 6, 2012 9:59:55 AM UTC-5, Larry Clapp wrote: > To answer your question, in the *buffer* package there are functions that > allow you to read directly from the buffer using regular Read calls.
I meant the *bytes *package.
-- L
You must
Sign in before you can post messages.
You do not have the permission required to post.