On Sunday, 25 July 2021 at 17:38:23 UTC, someone wrote:

i.e. your AA initialization is copy-pasted into each use of it, which means your program is rebuilding this AA at runtime every time it comes up. You probably got to this point as a bare `immutable structureLocations` errored out to the non-constant expression.

Sounds bad, inefficient at least :(

The whole point of a manifest constant is that it is purely a compile-time entity that does not exist at runtime. It has no address. In other words, `enum a = 10` can be seen as an alias to the integer literal `10`. That means anywhere you use `a`, it's just like you typed in `10` instead. It is *not* the same as a `const` or `immutable` value.

Think of them as a way to avoid "magic literals". Instead of typing `10` or `[1, 2, 3]` in multiple initializers or function calls, you use an alias instead, then when you decide to use `20` or `[2, 4, 6]` instead, you can simply change the declaration of the manifest constant instead of at multiple locations. But you're *still* effectively passing a literal. So if at certain points in your code you want to avoid any allocations a literal would trigger, then you shouldn't be using manifest constants at those points either.

Reply via email to