Jump to content
  • Advertisement
Sign in to follow this  
Nairou

Initialized structures - local or global?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!