Difference between `@(rodata)` global and a constant?

what’s the difference between:

@(rodata)
DIVIDE_BY_255_TABLE := [256]f32{ /*...*/ }

and

DIVIDE_BY_255_TABLE :: [256]f32{ /*...*/ }

as in why would you pick one over the other

As far as I understand it:

Globals with @(rodata) go into a read-only section in the binary, usages reference it by pointer.

@(rodata)
DIVIDE_BY_255_TABLE := [256]f32{ /*...*/ }

Globals go into a data section when the binary is loaded, usages reference it by pointer.

DIVIDE_BY_255_TABLE := [256]f32{ /*...*/ }

Constants only “exist” at compile time and get turned into (in this example, a shit-ton) of instructions. This can really blow up your code size if you use it many times.

DIVIDE_BY_255_TABLE :: [256]f32{ /*...*/ }

If you want to check for yourself, put your example into godbolt.org and select the Odin compiler.

1 Like