Hi everyone, I’m new to Elixir and reading about config files. From what I understand, the data in these files is stored in global memory. Is this correct or is the data used to generate a macro instead in order to decrease memory usage?
Configuration is both readable with
Application.get_env/2 and writable with
Application.put_env/3 - config is stored in memory.
Macros are a compile time thing so they don’t apply at runtime. Perhaps you meant “…generate a Module”. Configuration isn’t stored that way though.
Config files in Elixir are typically quite brief so therefore the concern around memory consumption isn’t raised (often?, ever?). Do you have a particular design consideration you’re working on?
If you have a larger amount of static data you want to have read access to at runtime then generating Modules at compile time to encapsulate data is quite common and doesn’t require a macro.
I’m planning to eventually implement an authorization-related library in Elixir so then there will be a nested map of permissions that needs to be stored somewhere. It’s probably not going to be prohibitively large in most cases, but it would be nice to get rid of that concern completely. My idea was to generate a function from the map at compile time that returns a literal from a key, so that’s why I figured it would be a macro. I’ll make sure to read up on Module generation also, thanks for the tip.