Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Map list of strings into memory
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
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:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Lukáš Zapletal  
View profile  
 More options Nov 5 2012, 4:56 pm
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter S  
View profile  
 More options Nov 5 2012, 10:44 pm
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel Pignatelli  
View profile  
 More options Nov 6 2012, 5:03 am
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:

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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Clapp  
View profile  
 More options Nov 6 2012, 9:59 am
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Clapp  
View profile  
 More options Nov 6 2012, 10:19 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »