On Sun, May 27, 2012 at 9:35 AM, John <
johns...@gmail.com> wrote:
> Preface: I'm no expert on mmap, I've read(and not completely
> understood) the man page for it. I've not used it before.
>
> I'm attempting to get better performance over a file I'm reading in.
> My problem state is:
>
> I get the following on cmd line:
> prog field1 regexp1 field2 regexp2 < file
>
> The file will have the top line as field names, and every other line
> as tab separated entries for those fields.
This doesn't sound like a good problem for mmap. Using mmap when
streaming a file probably won't help your performance. It really
shines when you want random access. I would suggest using a
bufio.Reader wrapping os.Stdin instead.
Your problem, however, has nothing to do with mmap.
> for data := range buffer.Next(1000) {
> fmt.Print(string(data))
> }
Here data is not a byte from the buffer, but an index into the buffer.
You're printing out the string conversion of the indexes 1, 2, 3, etc.
You want:
for _, data := range buffer.Next(1000) {
fmt.Print(string(data))
}
Or even better:
fmt.Print(string(buffer.Next(1000)))
- Evan