Anything other fundamental features of C# you're interested in? Let me know. Source code at: github.com/JasperKent/Val-and-Ref-Types Don't forget to subscribe at kzbin.info/door/qWQzlUDdllnLmtgfSgYTCA And if you liked it, click the 👍.
@finwwwfinwww466911 ай бұрын
If we have a structure with a string type (or class ) as one of its property, how are they handled, are they still placed on Stack , or just string property is explicitly placed on heap ?
@bioanu3 жыл бұрын
Excellent excellent excellent! Learning programming becomes simple when you are lucky enough to discover such a superb explanation!! Thank you very much!!
@alexpajp1232 жыл бұрын
This is the best explanation i've heard on this topic.
@ЕдвардГригорян-н6к3 жыл бұрын
Great video. The best explanation i have ever seen on KZbin
@CodingTutorialsAreGo3 жыл бұрын
Glad it was helpful!
@dolusdirectu3 жыл бұрын
Wow, the best explanation I have seen so far. Thx for this!
@yegorkatrechko1736 Жыл бұрын
Thanks a lot! That is really helpful, your explanation is clear and easy to understand!
@John_Macaroni2 жыл бұрын
awesome video, thanks!
@Fernando-mh7st2 жыл бұрын
Great explanation!
@zachgh61113 жыл бұрын
These are brilliant - keep up the great work and thanks for your time!
@CodingTutorialsAreGo3 жыл бұрын
Glad you like them!
@jonlicht45142 жыл бұрын
Well explained, thank you.
@nononnomonohjghdgdshrsrhsjgd Жыл бұрын
Very good! And how are the p1 p2 fred (names of objects) stored? In which part of the memory?
@CodingTutorialsAreGo Жыл бұрын
On the stack, as shown.
@nononnomonohjghdgdshrsrhsjgd Жыл бұрын
@@CodingTutorialsAreGo I meant the names itself. For example address 2 in stack memory contains a reference/address of where an object on the heap is stored. Where is the name p1 stored?
@CodingTutorialsAreGo Жыл бұрын
@@nononnomonohjghdgdshrsrhsjgd It's not. Local variable names are removed during compilation leaving only the positions on the stack.
@davidwhite20114 жыл бұрын
There is a good article that you can find on real world performance that you can google. "Stack allocation vs heap allocation - performance benchmark". But any way on 1 million loops with 10 allocation+init+free attempts, we see that difference is about 8% at 60KB total processing size. Which also also not a big show stopper.
@CuriousCyclist3 жыл бұрын
Love your videos. You should do a video about correctly implementing the Clone method/interface.
@CodingTutorialsAreGo3 жыл бұрын
I'll put it on the list.
@CuriousCyclist3 жыл бұрын
@@CodingTutorialsAreGo Thanks. I look forward to it.
@DedicatedManagers4 жыл бұрын
Another great explanation! Thank you! Also... what program did you use to create your sack pointer animation on the right side at the first half of the video?
@CodingTutorialsAreGo4 жыл бұрын
All done in Adobe Premiere Pro.
@DedicatedManagers4 жыл бұрын
@@CodingTutorialsAreGo I bet That took a fair amount of extra time. Well worth it though! It really made things clear. Thank you!
@CodingTutorialsAreGo4 жыл бұрын
Yeah, it takes a while. When I'm teaching live, I just use a virtual whiteboard, which does it in real time. But it's such a mess, I don't want it recorded for posterity.
@kiPROBRos3 жыл бұрын
Excelent tutorial, thanks.
@davidmoshkowitz40432 жыл бұрын
Amazing!!
@hristoiliev77673 жыл бұрын
What will happen in Stack if we have: var a = 5; a = 6; Will the compiler overrite the value of the existing variable "a" (5 to 6) OR It will create new object "a" with value of 6? Same question for string? var a = "aa"; a = "bb"; Will the compiler override the reference of "a" in the Stack OR Will create new object "a" with the newer reference?
@CodingTutorialsAreGo3 жыл бұрын
In the case of ints, a is an int and therefore a value type, so only one block of stack storage is created with a value 5 which is then overwritten to 6. (Actually, in this simple case the compiler might spot the optimisation and just set a directly to 6, but in general it overwrites.) In the string case, there will be one reference block allocated on the stack for a and two blocks on the heap, for "aa" and "bb". a will initially contain the reference to "aa" but will then be overwritten with the reference to "bb". (Again, assuming no compiler optimisations.)
@hristoiliev77673 жыл бұрын
@@CodingTutorialsAreGo Perfect! Thank you very much! :)
@mert.pinarbasi2 жыл бұрын
In Java we have Wrapper Classes to make primitive types to reference types.However in C# int is inherited from Object class.How can it is possible to both inherited and being stored in stack.What happens if I call toString() method on a int variable is it will be allocated to the heap?.I dont understand how it is possible to inherited from object if it is stored in stack it is the opposite of java.
@CodingTutorialsAreGo2 жыл бұрын
The fundamental thing that is required to allocate an object on the stack is that the compiler knows its size. It doesn't matter if it's inherited as long as the compiler knows the size of the overall object. In C++, for example, you can store anything on the stack, whatever the depth of the inheritance. What you can't do in C# is have a base class reference to a derived class object stored on the stack. C# cheats this using boxing. A C# box is the same concept as the Java wrapper, except that it is automatically created by the compiler, whereas in Java they are predefined (or they were last time I used Java - it may have moved on). See my video on boxing: kzbin.info/www/bejne/iGKYkpiMjryZfqc
@mert.pinarbasi2 жыл бұрын
@@CodingTutorialsAreGo Thanks for high quality videos and explanation.As I understand , when we call toString() method for example in a value type still it is stored in stack which is a great advantage if we compare the design preference with Java.Because there is no need boxing nor wrapper classes to use methods like toString if we want to use them.So, when I call an toString method in int value is c# compiler does autoboxing ?
@CodingTutorialsAreGo2 жыл бұрын
@@mert.pinarbasi When you call ToString on a value type (e.g. int) then the value type remains on the stack. There is no boxing. The int remains on the stack. The returned string, obviously, must be on the heap.
@Pluvo2for19 ай бұрын
I like to think of passing by reference as passing by value. Instead of passing a copy of a normal value type, we pass a copy of a memory address on the heap.
@kiPROBRos3 жыл бұрын
12:56
@jonjondi38455 ай бұрын
thank you sir
@zanagi9 ай бұрын
lul c# is really funny when one comes from c++ background... I was so lost.