B
B
bashtanka942015-02-10 23:02:49
.NET
bashtanka94, 2015-02-10 23:02:49

Where is a static class variable stored in .Net?

I wondered where a static variable is stored in .net? But I didn't find the exact answer...
As far as I understood, they are stored in the object of the type, which means in the heap... Therefore, every time they are accessed, they are unpacked?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Silin, 2015-02-10
@byme

google help:
stackoverflow.com/questions/337019/hows-memory-all...

M
mayorovp, 2015-02-11
@mayorovp

No, there is no unpacking. Unpacking is needed when explicitly converting an object into a value - the ldfld operation immediately receives the value.
Implementation details (where it is stored) are irrelevant in this plan.

M
MrDywar Pichugin, 2015-02-22
@Dywar

The static variable is stored in 1 instance in memory, and the assembly meta data on the HDD.
Object - stores all static fields and methods (Flyweight pattern).
Instance - stores all non-static fields of the class. (otherwise it would store immutable copies of duplicate data).
On Youtube channel ITVDN, a lecture from the course "C # Basic" is available for free, take a look.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question