Re: globals
Originally Posted by
noobermin
That's nice and all, but how about when you have large resources (image files, etc.) that you'd rather be global to all parts of the program and can't simply be defined on the stack? I can define the pointer on the stack in one file then have others have an extern in the other files, but yes, the actual data is on the heap.
You're given a relatively small amount of memory on the stack to work with, whereas the amount of heap space you're allowed to request scales with the amount of available memory. Thus, big things go on the heap, and small local things go on the stack.
How is that a problem? Unless you just are sloppy?
You run the risk of corrupting the stack. Taking a random global that you may or may not know the size of and manipulating it is asking for a buffer overflow. It's not as big of a deal on small projects where one person is doing all of the coding, and would already know the details of the implementation.
Posting code? Use the [code] or [php] tags.
I don't care, I'm still free. You can't take the sky from me.
Bookmarks