On Wed, Oct 27, 2021 at 3:34 PM jlfo...@berkeley.edu
<jlforr...@berkeley.edu> wrote:
>
> I'm asking because preinitializing an executable binary, where possible, 
> seems like an obvious optimization.
> I'm writing baby programs as I'm learning Go, but even they have a 
> significant (to me) number of initializations
> that don't need to take up any execution time. On the other hand, modern 
> computers are so fast maybe it's not
> even worth paying attention to such things.
>
> I'm not an expert but I don't think the example you showed says anything 
> about preinitialized data. For example,
> I built the following trivial program:
>
> package main
>
> var x = []int {1,2,3,4,5,6,7,8}
> var s string = "abcdefg"
> var p float64 = 3.1415
>
> func main() {
> }
>
> and then ran nm on the executable. I didn't see any sign of any of the 
> constants in my program. But,
> maybe I don't know what to look for. Your example shows data, but not 
> initialized data. Please
> correct me.

The constants won't be in that program because nothing refers to them,
so the compiler will discard them.

Try a program where the constants are actually used.  For example,
print them out.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXtT1GU0OR1TPM5gN1RwBnct0DuUU-Bd7ii-bYVMgjGuA%40mail.gmail.com.

Reply via email to