FAQ
package main

import (
"fmt"
"os"
"bufio"
)

func main() {
f, err:=os.Create("out.txt")
if err!=nil {
fmt.Println(err)
return
}
w:=bufio.NewWriterSize(bufio.NewWriter(f), 8192)
for i:=0; i < 100; i++ {
w.WriteString("ABC\r\n")
}
w.Flush()
f.Close()
}

Nothing is written to out.txt.


Env:
set GOARCH=386
set GOBIN=
set GOCHAR=8
set GOEXE=.exe
set GOGCCFLAGS=-g -O2 -m32 -mthreads
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=d:\temp\go\zetowr
set GOROOT=d:\programy\go
set GOTOOLDIR=d:\programy\go\pkg\tool\windows_386
set CGO_ENABLED=1

go version devel +c3570e8ed478 Wed Oct 10 13:29:50 2012 +1100

--

Search Discussions

  • Jan Mercl at Nov 13, 2012 at 9:50 am
    On Tue, Nov 13, 2012 at 10:43 AM, wrote:

    I think you have a two level buffer and you're flushing only the outer one.
    w:=bufio.NewWriterSize(bufio.NewWriter(f), 8192)
    I believe you want instead:

    w := bufio.NewWriterSize(f, 8192)

    -j

    --
  • Michal at Nov 13, 2012 at 10:11 am
    No, i want what I wrote. I have a function: func f(wr *bufio.Writer) and I
    want to make sure that the buffer is as large as I wish.

    michal

    W dniu wtorek, 13 listopada 2012 10:50:22 UTC+1 użytkownik Jan Mercl
    napisał:
    On Tue, Nov 13, 2012 at 10:43 AM, <mic...@zeto.wroc.pl <javascript:>>
    wrote:

    I think you have a two level buffer and you're flushing only the outer
    one.
    w:=bufio.NewWriterSize(bufio.NewWriter(f), 8192)
    I believe you want instead:

    w := bufio.NewWriterSize(f, 8192)

    -j
    --
  • Zizon Qiu at Nov 13, 2012 at 10:19 am
    this explain more
    http://golang.org/src/pkg/bufio/bufio.go?s=10514:10550#L414

    you flush a bufio with buffer size 8192 to another bufio which has the
    default buffer size(4096).
    nothing will be wrote until you Write more than 8192 bytes.
    On Tue, Nov 13, 2012 at 6:11 PM, wrote:

    No, i want what I wrote. I have a function: func f(wr *bufio.Writer) and I
    want to make sure that the buffer is as large as I wish.

    michal

    W dniu wtorek, 13 listopada 2012 10:50:22 UTC+1 użytkownik Jan Mercl
    napisał:
    On Tue, Nov 13, 2012 at 10:43 AM, wrote:

    I think you have a two level buffer and you're flushing only the outer
    one.
    w:=bufio.NewWriterSize(bufio.**NewWriter(f), 8192)
    I believe you want instead:

    w := bufio.NewWriterSize(f, 8192)

    -j
    --

    --
  • Michal at Nov 13, 2012 at 10:58 am
    Ok, it is alright now. Thans !

    W dniu wtorek, 13 listopada 2012 11:19:18 UTC+1 użytkownik Zizon Qiu
    napisał:
    this explain more
    http://golang.org/src/pkg/bufio/bufio.go?s=10514:10550#L414

    you flush a bufio with buffer size 8192 to another bufio which has the
    default buffer size(4096).
    nothing will be wrote until you Write more than 8192 bytes.

    On Tue, Nov 13, 2012 at 6:11 PM, <mic...@zeto.wroc.pl <javascript:>>wrote:
    No, i want what I wrote. I have a function: func f(wr *bufio.Writer) and
    I want to make sure that the buffer is as large as I wish.

    michal

    W dniu wtorek, 13 listopada 2012 10:50:22 UTC+1 użytkownik Jan Mercl
    napisał:
    On Tue, Nov 13, 2012 at 10:43 AM, wrote:

    I think you have a two level buffer and you're flushing only the outer
    one.
    w:=bufio.NewWriterSize(bufio.**NewWriter(f), 8192)
    I believe you want instead:

    w := bufio.NewWriterSize(f, 8192)

    -j
    --

    --
  • Dave Cheney at Nov 13, 2012 at 9:54 am
    There are three error results you have ignored, what are they telling you ?
    On 13/11/2012, at 20:43, michal@zeto.wroc.pl wrote:

    package main

    import (
    "fmt"
    "os"
    "bufio"
    )

    func main() {
    f, err:=os.Create("out.txt")
    if err!=nil {
    fmt.Println(err)
    return
    }
    w:=bufio.NewWriterSize(bufio.NewWriter(f), 8192)
    for i:=0; i < 100; i++ {
    w.WriteString("ABC\r\n")
    }
    w.Flush()
    f.Close()
    }

    Nothing is written to out.txt.


    Env:
    set GOARCH=386
    set GOBIN=
    set GOCHAR=8
    set GOEXE=.exe
    set GOGCCFLAGS=-g -O2 -m32 -mthreads
    set GOHOSTARCH=386
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=d:\temp\go\zetowr
    set GOROOT=d:\programy\go
    set GOTOOLDIR=d:\programy\go\pkg\tool\windows_386
    set CGO_ENABLED=1

    go version devel +c3570e8ed478 Wed Oct 10 13:29:50 2012 +1100
    --
    --
  • Michal at Nov 13, 2012 at 10:00 am
    Two iterations:

    Write n, err: 5 <nil>
    Write n, err: 5 <nil>
    Flush err: <nil>

    michal

    W dniu wtorek, 13 listopada 2012 10:43:35 UTC+1 użytkownik
    mic...@zeto.wroc.pl napisał:
    package main

    import (
    "fmt"
    "os"
    "bufio"
    )

    func main() {
    f, err:=os.Create("out.txt")
    if err!=nil {
    fmt.Println(err)
    return
    }
    w:=bufio.NewWriterSize(bufio.NewWriter(f), 8192)
    for i:=0; i < 100; i++ {
    w.WriteString("ABC\r\n")
    }
    w.Flush()
    f.Close()
    }

    Nothing is written to out.txt.


    Env:
    set GOARCH=386
    set GOBIN=
    set GOCHAR=8
    set GOEXE=.exe
    set GOGCCFLAGS=-g -O2 -m32 -mthreads
    set GOHOSTARCH=386
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=d:\temp\go\zetowr
    set GOROOT=d:\programy\go
    set GOTOOLDIR=d:\programy\go\pkg\tool\windows_386
    set CGO_ENABLED=1

    go version devel +c3570e8ed478 Wed Oct 10 13:29:50 2012 +1100
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 13, '12 at 9:43a
activeNov 13, '12 at 10:58a
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase