6

From my understanding, the Stack is used to store value types (like Enumerations and Structures) and variables which are referenced to objects (like class instances) in the Heap. Furthermore, the Stack also holds function calls with their respective parameters and the like in a LIFO manner.

In C, there are 4 generic memory segments (Heap, Stack, Data, Code) where the Data segment(s) usually store the global and static variables which implies a completely separate aspect of memory where they are stored and managed, but I do believe Java handles it differently (with some magic on the part of the JVM).

How/where would a variable be stored if I declared a global variable in Swift? Would this be different if I simply played around with a Playground file, for example, compared to declaring a global/static variable/function in a project module in XCode?

trincot
  • 317,000
  • 35
  • 244
  • 286
Mercato
  • 559
  • 4
  • 12
  • if you want to store a variable globally make use of user defaults or just make use of app delegate to store variable and access anywhere you want . Should I show some demo For Appdelgate ? – iOS Geek Aug 10 '17 at 05:34
  • 1
    thanks for the offer but you misunderstand; im not asking where I can store them in the writing of the code, I'm referring to where they are stored in the memory of the device itself – Mercato Aug 10 '17 at 06:32

0 Answers0