Re: [go-nuts] Does go dep support post install script like in php composer?

2018-08-27 Thread Miguel Angel Rivera Notararigo
Do you use a Makefile?

.PHONY: deps
deps:
  dep ensure
  path/to/the/script.sh

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread keith . randall
FYI shrinking maps on delete is issue 20135 
.

On Monday, August 27, 2018 at 12:13:00 PM UTC-7, Kasun Vithanage wrote:
>
> thanks this answer will work
>
> On Monday, August 27, 2018 at 9:56:16 PM UTC+5:30, Jake Montgomery wrote:
>>
>> Just to be clear, the memory used by the values *are *freed. In your 
>> example, those are the Person structs. It is only the internal memory used 
>> by the map that is not freed. See https://play.golang.org/p/fWOIbvjFjyB. 
>> In that test, the "internal" memory that is not freed is about 14 bytes per 
>> entry. 
>>
>> Of course, keep in mind that nothing is freed until a GC is done. 
>>
>> On Monday, August 27, 2018 at 5:00:14 AM UTC-4, Kasun Vithanage wrote:
>>>
>>> I've a map which has set of keys and pointing to some structs like this. 
>>> In here i allocate lot of entries and trying to delete them. But the memory 
>>> usage is not shrinking.
>>>
>>> According to this issue  it 
>>> seems how go behave at this point. In there its suggested to create a new 
>>> map and move all data there for reduced memory usage. But that seems not a 
>>> better option as it 
>>> is an expensive operation against such large map.
>>>
>>> What is the best way to delete a key from map freeing the memory 
>>> occupied by the Value(a pointer in this case).
>>>
>>> type Person struct {
>>>Name string
>>> }
>>>
>>> func NewPerson(name string) *Person {
>>>   return {Name: name}
>>> }
>>>
>>> func main() {
>>>   m := make(map[int]*Person)
>>>
>>> for i := 0; i < 10; i++ {
>>>   m[i] = NewPerson("Person" + strconv.Itoa(i))
>>>}
>>>
>>> for index := 0; index < 1; index++ {
>>>   m[index] = nil
>>>  delete(m, index)
>>>}
>>> }
>>>
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] `exec: "gcc": executable file not found in $PATH` when compiling as a module

2018-08-27 Thread Kevin Bowrin
>From Russ Cox on Twitter:

Because the pre-built packages are non-module builds and can’t be reused.
Sorry. Disable cgo for now or install gcc.

https://twitter.com/_rsc/status/1034143103509311493?s=19


On Mon., Aug. 27, 2018, 5:14 p.m. ,  wrote:

> https://gist.github.com/kevinbowrin/5f93152fdac23529e06a3a38cde88ce8
>
>
> Compiling this little program:
>
> package main
>
>
> import (
> "fmt"
> "net/http"
> )
>
>
> func main() {
> x, _ := http.NewRequest("GET", "https://google.com;, nil)
> fmt.Println(x)
> }
>
> in the GOPATH works fine.
>
> But if it is compiled as a Go 1.11 module outside the GOPATH, the error:
>
> exec: "gcc": executable file not found in $PATH
>
> is returned.
>
> I know I can `CGO_ENABLED=0 go build`. I'm more curious why 'mod-ing' this
> package causes the change in behavior.
>
> Thanks all.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/Ty3CXkMygIo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: `exec: "gcc": executable file not found in $PATH` when compiling as a module

2018-08-27 Thread thepudds1460
Hi all,

In a separate (short) forum, Russ wrote:

   "Because the pre-built packages are non-module builds and can’t be 
reused. Sorry. Disable cgo for now or install gcc."

I suspect these are related as well:

   #26993 -- "cmd/go: prebuilt net/http not used"
   https://github.com/golang/go/issues/26993


   #26988 -- cmd/go: GO111MODULE=on go build requires gcc 
   https://github.com/golang/go/issues/26988

But I would be curious to hear any additional commentary...

--thepudds

On Monday, August 27, 2018 at 5:14:18 PM UTC-4, Kevin Bowrin wrote:
>
> https://gist.github.com/kevinbowrin/5f93152fdac23529e06a3a38cde88ce8
>
>
> Compiling this little program:
>
> package main
>
>
> import (
> "fmt"
> "net/http"
> )
>
>
> func main() {
> x, _ := http.NewRequest("GET", "https://google.com;, nil)
> fmt.Println(x)
> }
>
> in the GOPATH works fine.
>
> But if it is compiled as a Go 1.11 module outside the GOPATH, the error:
>
> exec: "gcc": executable file not found in $PATH
>
> is returned. 
>
> I know I can `CGO_ENABLED=0 go build`. I'm more curious why 'mod-ing' this 
> package causes the change in behavior.  
>
> Thanks all.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] `exec: "gcc": executable file not found in $PATH` when compiling as a module

2018-08-27 Thread kjbowrin

https://gist.github.com/kevinbowrin/5f93152fdac23529e06a3a38cde88ce8


Compiling this little program:

package main


import (
"fmt"
"net/http"
)


func main() {
x, _ := http.NewRequest("GET", "https://google.com;, nil)
fmt.Println(x)
}

in the GOPATH works fine.

But if it is compiled as a Go 1.11 module outside the GOPATH, the error:

exec: "gcc": executable file not found in $PATH

is returned. 

I know I can `CGO_ENABLED=0 go build`. I'm more curious why 'mod-ing' this 
package causes the change in behavior.  

Thanks all.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: GoAWK: an AWK interpreter written in Go

2018-08-27 Thread Scott Pakin
On Friday, August 24, 2018 at 3:13:25 PM UTC-6, Ben Hoyt wrote:
>
> I recently wrote an AWK interpreter in Go: 
> https://github.com/benhoyt/goawk
>
> It's a pretty simple implementation: hand-rolled lexer, recursive-descent 
> parser, and tree-walk interpreter. It's pretty complete according to the 
> POSIX spec, and it passes the AWK ("one true awk") test suite as well as my 
> own unit tests.
>
> In some quick tests I ran, I/O speed is on a par or better than AWK but 
> the interpreter itself is quite slow -- about 5x slower for a lot of 
> things. I hope to add some proper benchmarks soon. I have a pretty good of 
> why and how to fix it: variable lookup and assignment is slow, and I'm 
> planning to fix by resolving more things at parse time.
>
> One thing that's a bit funky about AWK is its type handling: string values 
> can be real strings or "numeric strings" (numbers that came from user 
> input). I'm currently passing the "value" struct (see interp/value.go) 
> around by value. I still need to test if that's a good idea 
> performance-wise or not.
>
> I'd love to hear any comments, bug reports, or -- especially -- code 
> reviews.
>

Once you have some proper benchmarks, it might be fun to compare GoAWK's 
performance to that of my awk package .  The 
package implements AWK semantics in Go so a typical program is far more 
verbose than it would be in AWK but integrates tightly with Go code (e.g., 
one can use arbitrary Go code within the body of an AWK action).  GoAWK 
seems a lot easier to use when that level of integration is not needed, 
however.

I don't know how much performance difference this makes in practice, but my 
value struct (also in a value.go file) lazily converts among strings, 
floats, and ints and caches the conversions.  I don't keep track of "the" 
type of a value (your typ field), just whether I have a currently valid 
string/float/int representation.

No need to change your lexer/parser at this stage, but I've recently grown 
quite fond of PEG parsers 
.  These are a 
lot like hand-rolled, recursive-descent parsers so they're relatively easy 
to wrap your head around and reasonably powerful but require less 
code/effort than actually rolling your own.  For Go, I've used pigeon 
 for a few projects (e.g., edif2qmasm 
, for which a PEG parser is probably 
overkill).  I like pigeon, but I admit I didn't do a thorough analysis of 
all the available PEG parsers for Go before going with that one.

Nice work!

— Scott

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Kasun Vithanage
thanks this answer will work

On Monday, August 27, 2018 at 9:56:16 PM UTC+5:30, Jake Montgomery wrote:
>
> Just to be clear, the memory used by the values *are *freed. In your 
> example, those are the Person structs. It is only the internal memory used 
> by the map that is not freed. See https://play.golang.org/p/fWOIbvjFjyB. 
> In that test, the "internal" memory that is not freed is about 14 bytes per 
> entry. 
>
> Of course, keep in mind that nothing is freed until a GC is done. 
>
> On Monday, August 27, 2018 at 5:00:14 AM UTC-4, Kasun Vithanage wrote:
>>
>> I've a map which has set of keys and pointing to some structs like this. 
>> In here i allocate lot of entries and trying to delete them. But the memory 
>> usage is not shrinking.
>>
>> According to this issue  it 
>> seems how go behave at this point. In there its suggested to create a new 
>> map and move all data there for reduced memory usage. But that seems not a 
>> better option as it 
>> is an expensive operation against such large map.
>>
>> What is the best way to delete a key from map freeing the memory occupied 
>> by the Value(a pointer in this case).
>>
>> type Person struct {
>>Name string
>> }
>>
>> func NewPerson(name string) *Person {
>>   return {Name: name}
>> }
>>
>> func main() {
>>   m := make(map[int]*Person)
>>
>> for i := 0; i < 10; i++ {
>>   m[i] = NewPerson("Person" + strconv.Itoa(i))
>>}
>>
>> for index := 0; index < 1; index++ {
>>   m[index] = nil
>>  delete(m, index)
>>}
>> }
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread jake6502
Just to be clear, the memory used by the values *are *freed. In your 
example, those are the Person structs. It is only the internal memory used 
by the map that is not freed. See https://play.golang.org/p/fWOIbvjFjyB. In 
that test, the "internal" memory that is not freed is about 14 bytes per 
entry. 

Of course, keep in mind that nothing is freed until a GC is done. 

On Monday, August 27, 2018 at 5:00:14 AM UTC-4, Kasun Vithanage wrote:
>
> I've a map which has set of keys and pointing to some structs like this. 
> In here i allocate lot of entries and trying to delete them. But the memory 
> usage is not shrinking.
>
> According to this issue  it 
> seems how go behave at this point. In there its suggested to create a new 
> map and move all data there for reduced memory usage. But that seems not a 
> better option as it 
> is an expensive operation against such large map.
>
> What is the best way to delete a key from map freeing the memory occupied 
> by the Value(a pointer in this case).
>
> type Person struct {
>Name string
> }
>
> func NewPerson(name string) *Person {
>   return {Name: name}
> }
>
> func main() {
>   m := make(map[int]*Person)
>
> for i := 0; i < 10; i++ {
>   m[i] = NewPerson("Person" + strconv.Itoa(i))
>}
>
> for index := 0; index < 1; index++ {
>   m[index] = nil
>  delete(m, index)
>}
> }
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Does go dep support post install script like in php composer?

2018-08-27 Thread 'Tony Bamboni' via golang-nuts
Hi,
I read the dep documentation but was not aware of any hint in it if go dep 
can handle post install script like in PHP composer. 
How nice would be a solution to start a bash script automatically right 
after dep install is executed. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread ojucie
Replace your 1 billion entry map with a large number of small maps.
When you need to remove an entry you just substitute a small map.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] sync.(*Map).Load: relocation target sync/atomic.(*Value).Load not defined when building for ios_arm

2018-08-27 Thread Steeve Morin
Hey folks,

I'm trying to build a project with Bazel on with buildmode=c-archive, and 
I'm running into the following issue on ios_arm and Go 1.11 only:

sync.(*Map).Load: relocation target sync/atomic.(*Value).Load not defined
sync.(*Map).Store: relocation target sync/atomic.(*Value).Load not defined
sync.(*Map).LoadOrStore: relocation target sync/atomic.(*Value).Load not 
defined
sync.(*Map).dirtyLocked: relocation target sync/atomic.(*Value).Load not 
defined
internal/testlog.Logger: relocation target sync/atomic.(*Value).Load not 
defined

Go 1.10 works fine.

Now I know this is probably something that rules_go is doing wrong, because 
gomobile is working as expected.
That said, I am not sure where to look on how to pinpoint the issue, so I 
would gladly appreciate pointers.

The revelant rules_go issue is 
at: https://github.com/bazelbuild/rules_go/issues/1693#issuecomment-416081365

There was a similar problem with ios_386 which was solved by not building 
the stdlib with -shared.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to post Form data using Go WASM?

2018-08-27 Thread Tad Vizbaras
I am struggling to get this working. 

How to post Form data to the web server using Go WASM?
Do I use fetch API or XMLHttpRequest?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] internal compilation error while compiling gccgo from source solaris 10

2018-08-27 Thread Amandeep Gautam
Hi Ian,
   Thank you so much for the help. Both of those options did not work. 
Somehow, the program was able to get buggy libmpfr. I think it might be 
because I am using /usr/ccs/bin/ld and that ld is giving preference to 
libraries in /usr/lib. 
  In my case, /usr/lib/libmpc.so.3 pointed to /opt/csw/lib/libmpc.so.3 and 
that is how it was reaching to the buggy libmpfr. I changed the symlink for 
mpc/mpfr/gmp libs to point to the libs I have installed and it worked.

On Saturday, August 25, 2018 at 10:25:39 AM UTC-7, Ian Lance Taylor wrote:
>
> On Fri, Aug 24, 2018 at 11:48 PM, Amandeep Gautam 
> > wrote: 
> > Hi Ian, 
> >I compiled GMP, MPFR and MPC from source. Next, I configured gcc with 
> > modified options: 
> > 
> > $srcdir/configure \ 
> > --prefix=$prefix \ 
> > --enable-languages=go \ 
> > --with-as=/opt/csw/gnu/as --with-gnu-as \ 
> > --with-ld=/usr/ccs/bin/ld --without-gnu-ld \ 
> > --with-gmp-include=/usr/gnu/gmp/include 
> --with-gmp-lib=/usr/gnu/gmp/lib 
> > \ 
> > --with-mpfr=/usr/gnu/mpfr --with-mpfr-include=/usr/gnu/mpfr/include 
> > --with-mpfr-lib=/usr/gnu/mpfr/lib \ 
> > --with-mpc=/usr/gnu/mpc \ 
> > --with-isl=/opt/csw --with-isl-include=/opt/csw/include 
> > --with-isl-lib=/opt/csw/lib \ 
> > --with-build-time-tools=/opt/csw/gnu \ 
> > --enable-multilib \ 
> > --enable-shared \ 
> > --enable-static \ 
> > --disable-nls \ 
> > --disable-libquadmath \ 
> > --disable-libssp \ 
> > --disable-lto \ 
> > --disable-libgomp 
> > 
> > The make step is still failing but, to my surprise, I found that it is 
> still 
> > able to find libmpfr.so.4 from the /opt/csw directory. I am guessing 
> that I 
> > am not configuring something correctly. Can you please look. 
>
> Maybe you need to set LD_LIBRARY_PATH to point to your newly built 
> libmpfr? 
>
> Another approach is to copy the mpfr sources into your GCC directory, 
> named exactly mpfr.  Then the GCC build will automatically use that 
> one. 
>
> Ian 
>
>
>
>
> > Output from GBD: 
> > 
> > -bash-3.2$ gdb /export/home/amandeep/gccgo-obj/./gcc/go1 
> > GNU gdb (GDB) 7.7 
> > Copyright (C) 2014 Free Software Foundation, Inc. 
> > License GPLv3+: GNU GPL version 3 or later 
> >  
> > This is free software: you are free to change and redistribute it. 
> > There is NO WARRANTY, to the extent permitted by law.  Type "show 
> copying" 
> > and "show warranty" for details. 
> > This GDB was configured as "sparc-sun-solaris2.10". 
> > Type "show configuration" for configuration details. 
> > For bug reporting instructions, please see: 
> > . 
> > Find the GDB manual and other documentation resources online at: 
> > . 
> > For help, type "help". 
> > Type "apropos word" to search for commands related to "word"... 
> > Reading symbols from /export/home/amandeep/gccgo-obj/./gcc/go1...done. 
> > (gdb) run /export/home/amandeep/gccgo-src/libgo/go/fmt/doc.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/format.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/print.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/scan.go -quiet -dumpbase 
> doc.go 
> > -mcpu=v9 -auxbase-strip .libs/fmt.o -g -O2 -version -fgo-pkgpath=fmt 
> -fPIC 
> > -I . -L/export/home/amandeep/gccgo-obj/./gcc -o /var/tmp//ccBuuCrV. 
> > Starting program: /export/home/amandeep/gccgo-obj/gcc/go1 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/doc.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/format.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/print.go 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/scan.go -quiet -dumpbase 
> doc.go 
> > -mcpu=v9 -auxbase-strip .libs/fmt.o -g -O2 -version -fgo-pkgpath=fmt 
> -fPIC 
> > -I . -L/export/home/amandeep/gccgo-obj/./gcc -o /var/tmp//ccBuuCrV. 
> > [Thread debugging using libthread_db enabled] 
> > [New Thread 1 (LWP 1)] 
> > GNU Go (GCC) version 8.2.1 20180814 (sparc-sun-solaris2.10) 
> > compiled by GNU C version 8.2.1 20180814, GMP version 6.1.2, 
> MPFR 
> > version 4.0.1-p13, MPC version 1.1.0, isl version csw-0.18-GMP 
> > 
> > warning: MPFR header version 4.0.1-p13 differs from library version 
> 4.0.0. 
> > warning: MPC header version 1.1.0 differs from library version 1.0.2. 
> > GGC heuristics: --param ggc-min-expand=100 --param 
> ggc-min-heapsize=131072 
> > GNU Go (GCC) version 8.2.1 20180814 (sparc-sun-solaris2.10) 
> > compiled by GNU C version 8.2.1 20180814, GMP version 6.1.2, 
> MPFR 
> > version 4.0.1-p13, MPC version 1.1.0, isl version csw-0.18-GMP 
> > 
> > warning: MPFR header version 4.0.1-p13 differs from library version 
> 4.0.0. 
> > warning: MPC header version 1.1.0 differs from library version 1.0.2. 
> > GGC heuristics: --param ggc-min-expand=100 --param 
> ggc-min-heapsize=131072 
> > /export/home/amandeep/gccgo-src/libgo/go/fmt/format.go:8:9: error: 
> import 
> > file 'strconv' 

[go-nuts] How to make UDP server performance better?

2018-08-27 Thread Zhuo Meng
Hi, Gophers

I'm doing benmarking for my GoNTPd   
.

I found that my implement is only can handle about 100Kpps (kilo packets 
per second) per goroutine while ntpd can handle about 170 Kpps. on Intel 
Xeon E312
The pprof shows most of function time spend on syscall.Syscall6 (Read/Write 
from UDP socket), how can I improve that?

Many thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Kasun Vithanage
Yeah saw that, but what about a map with around 10 entries. this 
will add a lot of overhead i guess.

On Monday, August 27, 2018 at 3:13:39 PM UTC+5:30, Jan Mercl wrote:
>
> On Mon, Aug 27, 2018 at 11:38 AM Kasun Vithanage  > wrote:
>
> > I simply want to delete the memory allocated by Value too. When i 
> checked memory with MemStats, its still same as when i added entries to map
>
> See https://github.com/golang/go/issues/20135#issuecomment-297490415
>
> "The only available workaround is to make a new map and copy in elements 
> from the old."
>
>
> -- 
>
> -j
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Jan Mercl
On Mon, Aug 27, 2018 at 11:38 AM Kasun Vithanage 
wrote:

> I simply want to delete the memory allocated by Value too. When i checked
memory with MemStats, its still same as when i added entries to map

See https://github.com/golang/go/issues/20135#issuecomment-297490415

"The only available workaround is to make a new map and copy in elements
from the old."


-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Kasun Vithanage
I simply want to delete the memory allocated by Value too. When i checked 
memory with MemStats, its still same as when i added entries to map

On Monday, August 27, 2018 at 3:02:53 PM UTC+5:30, Hau Ma wrote:
>
> I think there is a major different: the memory allocated for key "index" 
> in hashmap, if you assign m[index] to nil, the allocated memory for hashed 
> key "index" still exist, when delete the allocated memory will be deleted 
> as well. Both will have same affect on the pointer to struct, it will be 
> collected by Garbage Collector
>
>
> Vào Th 2, 27 thg 8, 2018 vào lúc 16:00 Kasun Vithanage <
> alan...@gmail.com > đã viết:
>
>> I've a map which has set of keys and pointing to some structs like this. 
>> In here i allocate lot of entries and trying to delete them. But the memory 
>> usage is not shrinking.
>>
>> According to this issue  it 
>> seems how go behave at this point. In there its suggested to create a new 
>> map and move all data there for reduced memory usage. But that seems not a 
>> better option as it 
>> is an expensive operation against such large map.
>>
>> What is the best way to delete a key from map freeing the memory occupied 
>> by the Value(a pointer in this case).
>>
>> type Person struct {
>>Name string
>> }
>>
>> func NewPerson(name string) *Person {
>>   return {Name: name}
>> }
>>
>> func main() {
>>   m := make(map[int]*Person)
>>
>> for i := 0; i < 10; i++ {
>>   m[i] = NewPerson("Person" + strconv.Itoa(i))
>>}
>>
>> for index := 0; index < 1; index++ {
>>   m[index] = nil
>>  delete(m, index)
>>}
>> }
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Hau Ma
I think there is a major different: the memory allocated for key "index" in
hashmap, if you assign m[index] to nil, the allocated memory for hashed key
"index" still exist, when delete the allocated memory will be deleted as
well. Both will have same affect on the pointer to struct, it will be
collected by Garbage Collector


Vào Th 2, 27 thg 8, 2018 vào lúc 16:00 Kasun Vithanage <
alanka...@gmail.com> đã viết:

> I've a map which has set of keys and pointing to some structs like this.
> In here i allocate lot of entries and trying to delete them. But the memory
> usage is not shrinking.
>
> According to this issue  it
> seems how go behave at this point. In there its suggested to create a new
> map and move all data there for reduced memory usage. But that seems not a
> better option as it
> is an expensive operation against such large map.
>
> What is the best way to delete a key from map freeing the memory occupied
> by the Value(a pointer in this case).
>
> type Person struct {
>Name string
> }
>
> func NewPerson(name string) *Person {
>   return {Name: name}
> }
>
> func main() {
>   m := make(map[int]*Person)
>
> for i := 0; i < 10; i++ {
>   m[i] = NewPerson("Person" + strconv.Itoa(i))
>}
>
> for index := 0; index < 1; index++ {
>   m[index] = nil
>  delete(m, index)
>}
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: os.WriteFile not writing files in long running process

2018-08-27 Thread Manlio Perillo
No, the file is not flushed on close.
https://linux.die.net/man/2/close

"A successful close does not guarantee that the data has been successfully 
saved to disk, as the kernel defers writes. It is not common for a file 
system to flush the buffers when the stream is closed. If you need to be 
sure that the data is physically stored use fsync 
(2). (It will depend on the disk 
hardware at this point.)"

You can just Sync the file, to make sure this not the problem.


Manlio

On Monday, August 27, 2018 at 10:19:37 AM UTC+2, Paweł Szczur wrote:
>
> If you're asking about dmesg, I'm not seeing anything related.
> Yes, I'm on linux. The dir was created successfully, I guess it was not a 
> problem. Also, I believe the file is flushed on Close.
>
> I will look into the link.
>
> Paweł
>
> On Friday, August 24, 2018 at 6:33:15 PM UTC+2, Manlio Perillo wrote:
>>
>> On Friday, August 24, 2018 at 4:19:17 PM UTC+2, Paweł Szczur wrote:
>>>
>>> Thanks. Both things you mentioned are already fixed. The MakeDir may of 
>>> course fail and now I handle it, but in described situation it was not an 
>>> issue.
>>> The files were written for most of the day successfully and suddenly 
>>> they stopped to appear.
>>> The disk was and is not full. There was no error returned by any 
>>> function (I've examined logs).
>>>
>>
>> Did you checked the system/kernel logs?
>>
>> If you still are unable to find the cause of the problem, and assuming 
>> you are on an UNIX system, you can try to change the code to make sure that 
>> both the new directory entry, and the new file data is flushed to disk.
>> For the directory entry you have to open the directory with os.OpenFile, 
>> passing the os.O_RDONLY|unix.O_DIRECTORY flags, and call Sync after the new 
>> file is created.
>>
>> See http://danluu.com/file-consistency/
>>
>>
>> Manlio
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] What is the proper way to delete a key which holding a pointer in a map

2018-08-27 Thread Kasun Vithanage
I've a map which has set of keys and pointing to some structs like this. In 
here i allocate lot of entries and trying to delete them. But the memory 
usage is not shrinking.

According to this issue  it 
seems how go behave at this point. In there its suggested to create a new 
map and move all data there for reduced memory usage. But that seems not a 
better option as it 
is an expensive operation against such large map.

What is the best way to delete a key from map freeing the memory occupied 
by the Value(a pointer in this case).

type Person struct {
   Name string
}

func NewPerson(name string) *Person {
  return {Name: name}
}

func main() {
  m := make(map[int]*Person)

for i := 0; i < 10; i++ {
  m[i] = NewPerson("Person" + strconv.Itoa(i))
   }

for index := 0; index < 1; index++ {
  m[index] = nil
 delete(m, index)
   }
}



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: os.WriteFile not writing files in long running process

2018-08-27 Thread Paweł Szczur
No.

On Friday, August 24, 2018 at 6:47:01 PM UTC+2, dja...@gmail.com wrote:
>
> Hi,
> did you write files in /tmp on linux ?
> (and there is daemon that clean old files in /tmp ?)
>
> Regards,
> Djadala
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.