Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:41:59+00:00 2026-05-24T02:41:59+00:00

I was wondering – how are objects stored int the memory? I already know

  • 0



I was wondering – how are objects stored int the memory?

I already know that there’s a reference (like a pointer) that is an int value containing the place in the memory where that object is stored – but how exactly is it stored?

Lets say I have ClassC that has int a, char b, long c, float d and short e – I know how each is stored each have their own set of bit but the amount of bits in each different – so how exactly does C# knows which bits should it access when I write OBJ.c or OBJ.b ?

Is it somewhat possible to convert a whole (nonstatic) object to an array of bytes\bit AND back?


OBVIOUSLY – If there’s something like ClassC.TcpListener tcp – it’s a reference and stored as an int (? Atleast it has the same size in bytes) – but still, how can it different between an int and a pointer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:41:59+00:00Added an answer on May 24, 2026 at 2:41 am

    Generally, this isn’t something you need to care about unless you’re P/Invoking a C library.

    so how exactly does C# knows which bits should it access when I write
    OBJ.c or OBJ.b ?

    It depends on the StructLayout of the object. There are two possible LayoutKinds.

    The default is Sequential, where fields are stored in the same order they are declared, aligned appropriately. By default, a struct containing your five fields would be stored as:

    • offset 0-3: int a
    • offset 4-5: char b
    • offset 6-7: padding
    • offset 8-15: long c
    • offset 16-19: float d
    • offset 20-21: short e

    A class may have a slightly different layout due to vtable pointers, garbage collector metadata, etc. I’m not sure exactly how it works.

    The other LayoutKind is Explicit, where you specify the field offsets explicitly.

    Is it somewhat possible to convert a whole (nonstatic) object to an array of bytes\bit AND back?

    Yes, the Marshal class will let you do this. See StructureToPtr and PtrToStructure.

    it’s a reference and stored as an int

    Pointers are not stored as ints. That wouldn’t work on 64-bit systems. IntPtr is used instead.

    but still, how can it different between an int and a pointer?

    At which level? C#? CIL? Machine language?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if there is any way to get the lambda expressions that result from
Wondering if anyone out there has ran into this before.... I'd like to use
wondering if there's any way to make it so that a list I have
Wondering if there's any jquery library/plugin that can easily perform the following. At main
Wondering if there is an existing ring buffer in .NET that has only one
Wondering if there is a way to change the object on the heap that
Wondering if there is any Text to Speech software available as a plug in
Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Wondering if this is possible. We have an 3rd Party library that contains identification

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.