Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Why does System.Int32 take 24 bytes?

If an int takes 4 bytes, why does System.Int32 takes 24 bytes when boxing an integer into an object?

For example:

int i = 3;
object o = i;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In C#/CLR reference types have some size overhead:

The layout of a managed object is pretty simple: a managed object contains instance data, a pointer to a meta-data (a.k.a. method table pointer) and a bag of internal information also known as an object header.

enter image description here

So when you box your int into the heap it will be stored as a reference type and will include all the extra info and then the memory will be aligned resulting in something like this:

Object Header (8 bytes)
Method Table Pointer (8 bytes)
Int (4 bytes)
padding (4 bytes, to align at 8 bytes)

Note that this is dependent on the bitness of the process (the breakdown above is for 64-bit case) and is actually runtime implementation detail (the previously linked article mentions at least one implementation which differs).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!