Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How big is an object reference in .NET?

Tags:

c#

.net

reference

What is the size of an object reference in .NET? Does it vary between x86, x64, and/or AnyCPU compilation?

If it makes a difference, I'm interested in C#.

like image 549
Matt Mills Avatar asked Sep 27 '10 03:09

Matt Mills


People also ask

How big is an object reference?

References have a typical size of 4 bytes on 32-bit platforms and on 64-bits platforms with heap boundary less than 32Gb (-Xmx32G), and 8 bytes for this boundary above 32Gb.

How much memory does a reference take in C#?

A reference consumes the native word size of the platform it is running on. That is, 32-bit: 32 bits. 64-bit: 64 bits.

What is the length of an object reference?

An object reference is basically a pointer to the memory that contains the object's attributes. As such the reference is one processor word in length - 32 bits on 32 bit platforms and 64 bits on x64. Thanks for contributing an answer to Stack Overflow!

How many bytes does it take to reference an object?

Each reference to an object requires an extra four or eight bytes, depending on whether the .NET runtime is running on a 32- or 64-bit platform.

How big is a reference in C++?

A reference is implemented as a pointer, so in an application that runs in x86 mode (32 bit), a reference is four bytes, and in x64 mode (64 bit), a reference is eight bytes. As the reference is just a pointer to an object, the reference is the same size regardless of what it is pointing to, or even if it doesn't point to anything at all (null).

How much memory does a reference type use?

From C# 5.0 in a Nutshell: The Definitive Reference in page 22; 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.


1 Answers

The reference itself is basically a pointer. 32 bits on a 32 bit OS, 64 bits on a 64 bit OS.

The size of the object that's referenced is more complicated.

like image 141
Samuel Neff Avatar answered Oct 12 '22 23:10

Samuel Neff