Storage overhead
Value-type instances occupy precisely the memory required to store their fields. In
this example, Point takes eight bytes of memory:
struct Point
{
int x; // 4 bytes
int y; // 4 bytes
}
Technically, the CLR positions fields within the type at an address
that’s a multiple of the fields’ size (up to a maximum of 8
bytes). Thus, the following actually consumes 16 bytes of memory
(with the 7 bytes following the first field “wasted”):
struct A { byte b; long l; }
Reference types require separate allocations of memory for the reference and object.
The object consumes as many bytes as its fields, plus additional administrative
overhead. The precise overhead is intrinsically private to the implementation of
the .NET runtime, but at minimum the overhead is eight bytes, used to store a key
to the object’s type, as well as temporary information such as its lock state for
multithreading and a flag to indicate whether it has been fixed from movement by
the garbage collector. Each reference to an object requires an extra 4 or 8 bytes,
depending on whether the .NET runtime is running on a 32- or 64-bit platform.
1) Is he saying that if I want to store a hundred byte types as data I'd be just as well off storing a hundred int types or float types because they all take up the same amount of space? Lol that's crazy, who's idea was that? I mean a Boolean already takes eight bits, which means that a boolean takes 64 bits now.
2) Also is he implying that a reference type (which I guess is like a pointer?) requires MORE data for the same thing? Shouldn't it contain JUST the administrative overhead or whatever? I mean I'm just pointing to the start of the memory right? Wait what the heckler is "additional administrative overhead" anyway? So pointing to a boolean takes some 16 bytes or something?
3) So structures, those are efficient instead, right? So if I store 4 bytes in a struct it's the same as storing one float right? I don't lose any space to craziness until I combine the two, right? Or is that just in the case of objects then? I thought structs were types and objects were types but I guess not.
This is so confusing, these questions probably don't even make sense lol. Am I even close to learning this right?
4) Here's a link to something that may or may not be related: http://www.simple-ta...llocation-cost/
According to the link arrays are good too, they don't waste any space like the objects or whatever.
But obviously you're not supposed to worry about these things but I would like to understand.
EDIT:
He goes on to say
Of the integral types, int and long are first-class citizens and are favored by both C#
and the runtime. The other integral types are typically used for interoperability or
when space efficiency is paramount.
But didn't he just say it doesn't matter? I must be mistaken. But it's what he said "a byte and a float take 16 bytes". He was talking about some special case then, I guess.






