Please clarify my understanding regarding the object and the link, and the type of value is current?

Clarify my understanding regarding the object and reference, and is the type of value current?

Object means the location of memory in RAM, where we allocate memory when the program is executed

Link means a location (address) in memory.

Passing by reference - we pass or point a memory cell to a function in order to take values ​​for the function from which the memory address was transferred.

Passing by value means that we are not specifying any address that gives the actual value of the function. Where does this value come from RAM? Does he touch during execution? It is sent only from another memory location ... but what is the difference in lead times in a visual context? how can i imagine

+4
source share
2 answers

I would not worry about RAM / etc.

The main difference here, conceptually, is that you move on to the method.

When you pass a link (ref or out in C #), you pass the location to the memory of the original object.

When you go through the value, you copy the actual value of the variable, and the method gets a full copy of the value of the variable that was used in the previous call stack.

If the variable is a reference type, the value passed is a reference to an object, which is basically a memory location. The link is copied to the method.

If the object in question is a value type, the entire object is copied, and the method receives a copy of the object.

+3
source

An object is an instance of class . The memory for the object and any items are stored in the heap. In general, this is called [ Reference Type][2] , which means that it is treated as a link (pointer) to a location.

Unlike a struct is a Value Type that is processed directly.

Passing a By Reference element ( ref keyword or out , as Reed points out) transfers a link (pointer) to the subject in question. This means that if you pass an object by reference, you pass a pointer to a pointer to an object in memory.

An object

  arg (stack) -> oRef (heap) -> oData (heap)

This means that we can change the pointer to another location (i.e. a completely different object).

Passing an element By value means transferring the object itself. In the case of structure, all this is pushed onto the stack. In the case of an object, the link is passed on the stack. This means that when an object is transferred, the object can still be involved and its members change, but it cannot be completely replaced by another object.

  arg (stack) -> oData (heap)
+1
source

Source: https://habr.com/ru/post/1302148/


All Articles