Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many bytes of memory does each type in .NET consume (32-bit environment)? [closed]

How much memory in bytes do types like int, bool, float, double, decimal, object, and string use when added as a field to an instance of a class?

like image 459
user1306322 Avatar asked Nov 12 '12 20:11

user1306322


People also ask

How many bytes does a float take?

Floating-point numbers use the IEEE (Institute of Electrical and Electronics Engineers) format. Single-precision values with float type have 4 bytes, consisting of a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa.

Why is int 4 bytes?

The fact that an int uses a fixed number of bytes (such as 4) is a compiler/CPU efficiency and limitation, designed to make common integer operations fast and efficient.


1 Answers

This page shows the size of each datatype in bits (divide by 8 to get bytes):

byte 8
sbyte 8
int 32
uint 32
short 16
ushort 16
etc...

Object and string are reference types. Reference types take up at least the size of all the fields they contain plus the size of the reference itself.

Related

  • How big is an object reference in .NET?
like image 197
Mark Byers Avatar answered Sep 22 '22 10:09

Mark Byers