D
D
Denis Bredun2020-07-09 19:00:52
C++ / C#
Denis Bredun, 2020-07-09 19:00:52

What are objects of primitive value, reference types?

Right now I'm studying reflection and what's going on under the hood. The line reached the fields. I first considered them as separate from ordinary objects (value or reference) entity, but I was mistaken, as Jeffrey Richter's book says that

A field is a data member that stores an instance of a value type or a reference to a reference type.
, that is, it's the same variable, only it has a different location, so now I'll treat fields as simple objects of a reference or value type, and not as something foreign. And here the question arises, what are objects of primitive meaningful, reference types? I know what an object of a self-made class looks like, I know about the method table and EEClass, but it seems to me that objects of primitive reference types differ from objects of self-made types, and I have never heard anything about the interiors of objects of primitive (and even not primitive) value types , for now. So here are a few specific questions:
1. What fields, methods, properties are inaccessible to the programmerreference and value types?
2. Do objects of primitive reference and value types have their own descriptors?
3. If the answer to question No. 2 is yes, then what fields, methods, properties are inaccessible to the programmer?
In the book of Richter and Goldstein, I did not find anything about this, I found there only a detailed description of the type created by my own hand.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2020-07-10
@yarosroman

Access modifiers allow you to hide members from the rest of the code, reflection allows you to get access to them, I don’t remember if private methods can be called. The second thing in the object is the internal structure of EEClass. In unsafe mode, you can also pull it out, get a table of virtual methods.

D
Dmitry Pavlov, 2020-07-09
@Stalker31

Difference between

public class A
{
public int _age = 19;
}

and
public static void Main()
   {
    int age = 19;
   }
is that 1 variable is at the class level, and the second at the method level. For example, you cannot access a method-level variable from a class or another method, but you can access a class-level variable both at the class level and at the method level.

N
none7, 2020-07-09
@none7

All ValueType properties are open, base types like int have no properties at all, they are nailed to ValueType for beauty. They are a storage for numbers, just a set of bits, there is simply nowhere to be more primitive, machine instructions work with them, not methods. In the case of local variables, they may well exist only in processor registers or even be erased as unnecessary. This is the difference between age and _age, there is no other difference. As far as methods, how should framework code call hidden methods? There is no such thing.
What kind of descriptors? Google finds file and window handles...
PS Advanced books assume you have a basic understanding of how computers work and understand C.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question