B
B
beduin012017-02-04 13:49:54
Programming
beduin01, 2017-02-04 13:49:54

What is the difference between reference and signed types?

Do I understand correctly that both types store the structure itself (a reference to it) on the stack, but signed ones also store its value on the stack, while reference types store a reference to the heap on the stack. So?
Are there any restrictions on the size of structures? Can I push a file onto the stack?
If I declared a structure,
struct MyStruct
{
//...
}
Is it correct to say that when I create a working object of this structure, I create an instance of it? Or how is it said? Are we "creating a variable with type MyStruct"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tom Nolane, 2017-02-04
@tomnolane

Value types store a value, while reference types store a reference to a value. Not significant))

class SSylka
{
    public byte Value { get; set; }
}

struct Znachenie {
    public byte Value { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        SSylka _ssylka = new SSylka { Value = 0 };
        Znachenie _znachenie = new Znachenie { Value = 0 };
    }
}

In the code, both _ssylka and _znachenie are created as local variables of the Main method on the stack. The _znachenie variable contains the Value, and the _ssylka variable contains a reference to the Value stored on the heap.
For reference types, it's a heap; for value types, it's a stack. In this case, the reference variable (the reference itself) is stored on the stack. Only instances of structures
(int, double, etc.) can be significant - these are structures
You* instantiate (not to be confused with a reference) a variable on the stack of type MyStruct
A stack is a last in, first out (LIFO) container.
This class creates a dynamic collection that grows as it needs to store input items. Whenever such a collection needs to be expanded, its capacity is doubled.
Those. you can, but why? It will be more optimized - if it is on the heap, so that the GC (garbage collector) deletes it when it is not needed .... and if the file changes? (increase / decrease?) .... and so each time it increases, it will not occupy all the "space" allocated for it ...

R
Rubka, 2017-02-04
@Rubka

As for the file, you definitely cannot hide the file on the stack, because Stream (the only way to work with the disk) is a reference type.
In any case - the standard stack size is 1Mb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question