Skip to main content
GameDev.net gamedev.net
🔒 Locked

Initialized structures - local or global?

Started by Nairou Nov 27, 2004 at 2:30 PM 0 replies 650+ views
Original Post
Nairou
Nairou
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?
SiCrane
SiCrane
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.