Playing a bit with Go I found something weird, I don't know if it may be a
compiler bug. I'm using Go 1.2 and I'm seen this in ARM, linux/386 and
windows/386.
I am creating a big array (not a slice) of a struct and then accessing it
with range using the index or the value. It seems that if the struct
contains a string (even if not used) AND the struct is accessed using the
value, compilation uses a lot of memory and the program produced is really
big or even fails to compile.
Cases:
- The version that fails (binary is about 10 MB, compiler uses about 180
MB): http://play.golang.org/p/EikUFnNvqj
Increasing array size causes it to use more RAM or even to fail if no more
RAM is available.
- String removed (works): http://play.golang.org/p/PuJWOf8hUz<http://play.golang.org/p/WgMquzjtnc>
- Access by value removed (works): http://play.golang.org/p/6OH7vXKDCa<http://play.golang.org/p/kTAR0UWXA2>
Some other errors I have seen, that I don't know if they are related:
- String removed but array increased to 1000000 elements:
http://play.golang.org/p/v7i1VWOFbg
Compiler says: main.main: overflow in spadj: 0 + 1200002464 = 1200002464
-Thomas Bushnell in G+ community says:
*Interestingly, if you replace "string" with [1000]int, you get a memory
error, but a stack overflow error, which shouldn't happen for this program
at all, which should use constant stack
space. http://play.golang.org/p/_itbrJzZvN
<http://play.golang.org/p/_itbrJzZvN>*
I know that I'm not being idiomatic, it is just a toy, but I don't know if
this behaviour is expected.
Any idea?
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.