# Initialized structures - local or global?

This topic is 5134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This feels like a really dumb question, but I'm not sure what the answer is and its been bugging me a while now. Lets say you have a data structure, which is pre-initialized, just used to hold a collection of read-only data (simple example):
char *prefixes[] = {
"Log",
"Init",
"Renderer",
"Net",
...etc...
};

Now, if I made this a global structure, I know that it would just be stored in the executable as data. Always available. But what if this structure was contained within a function, so it was just local data? Would it still be stored as data, or would the entire structure be constructed from scratch every time the function was called? Is the only alternative in this case to define it static?

##### Share on other sites
The prefixes array itself would be on the stack, and will need to be initialized each time the function is called, but the strings that it points to will probably be in a data segment of your executable.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×