Well, Before discussing what is Stack and Heap in c#. It would be better if you understand what is value type and
reference type. In c# values are divided into types:
1. Instance of value type
2. Instance of Reference type
3. References
Instance of value type includes following types(Primitive)
1.float,char,int,double,decimal etc except System.string
Instance Reference type:
1.class,object,string
References:
It is a datatype which contains address of another memory block.So, Value of references is an Address.
Now,
What is Stack and Heap or Difference between Stack and Heap
All instances of value type can be stored on Stack whereas instance of Reference type gets memory allocated from Heap.
Stack keep track of control flow and all variables gets disposed as variable goes out of scope.
Heap is used for dynamic memory allocation.
example.
STACK:
consider stack of book, and if you want the book at the bottom of stack then you have to go one by one to get required book.
HEAP:
Consider Table,on which books are kept but not stacked. Each book is kept separate. Now, if you want to access any book you can directly access that book.
you don't need to touch other book in order to get that required book.
I hope this information will reduce your search effort and you will get started with your Logger ASAP.
-Cheers.
No comments:
Post a Comment