I’ll be running throught the following terms, just a FYI and of course its to remind me again and again, time after time, how important knowing all this is!
There are two ways to allocate memory, that’s either Stack Or By Heap, I’m just dumbing it down for normal human consumption Here’s tthe pretty complex stuff
http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap
http://www.albahari.com/valuevsreftypes.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx (I Like this one)
Stack: The way stack manages data uses a simple first-in last-out memory structure different from the heap
Heap: Heap is known for dynamic memory allocation, which uses memory cleaner or garbage cleaners
Stack will store locally created variables( means inside of functions, cause stack is faster, and due to its structure its the best for this case) by reference or by value
Heap will store Objects that the pointers are pointing to, and anything thats structured, like STRUCTS..
Well lets look at it this way, Stack is like a mailing company, and heap is like a Storage company, if we want to store or manipulate data fast, and a while i would go for stack,if we want to go store information longer, I’ll go to heap! that’s one way to look at it.. well don’t trust my words for it go read up the articles that i gave you!
Okay now im gonna talk about Ref,values, and pointers. passing something by reference means im actually passing a pointer to that object, means i now can tweak that object that you find in the heap.. so i can have many pointers,pointing to one object, this gives us two things,one is i now can pass this information without having an overhead of copying or duplicating information ( this would take up heap memory of course). And second is i can easily tweak the values of the object as i pass the pointers around the project!…
Now passing value, means im creating a copy of the object and passing that copied object, so now in your heap, or your stack depending on where you declare you have a copy.
Pointers are the coolest thing in programming if you ask me, i’m doing c# now..But i miss playing with pointers in c++, forgot a lot of stuff though, thats why i have this blog!
Anyways i’ll summarise and i’ll talk about why i’m writing about this.
1. I’m developing in XNA, and when i publish on the XBOX, the frame rate drops!, its a simple reason, and thats cause of the garbage collector, that works differently on the XBOX then on the PC, (.NET) and (.NETCOMPACT). So understanding this very big concept is a must, if we are going to talk about optimization. So if i was to use what i learnt, due to objects in the heap, not being used cause there is no reference pointing to it, i am making the Garbage cleaner clean up that unused object, and i’m having tons of them. So tons more work for the garbage collector.
Anyways, i hope you learnt something or found out that i suck at explaining, or got my concepts all wrong….Well if you can’t trust my words follow the links.. You’ll learn tons!
Cheerios Peeps,
Ikhwan
p.s Have to remind myself to post later today, about my current project