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 959127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:58:35+00:00 2026-05-16T00:58:35+00:00

public class MyClass { int i = 0; string str = here; MyStruct mystruct;

  • 0
public class MyClass
{
    int i = 0;
    string str = "here";
    MyStruct mystruct;
    B b;
    ArrayList myList = new ArrayList(10);

    public MyClass()
    {
    }
    ....
}

public struct MyStruct
{
    public int i;
    public float f;
}

public class B
{
    ...
}

Want to learn how an instance of a class is created in the background. When this statement

 MyClass myClass = new MyClass();

is evaluated. What will happen in the backgroud? My following statements are correct or not (for 32-bit OS machine)?

  1. A memory space will be created and referenced as myClass;
  2. within above memory space, 4 bytes is used for the value of int i;
  3. within above memory space, 4 bytes is used for the reference of string str; the actual value of the str is stored in other location (where?)
  4. within above memory space, 8 bytes is used for the value of MyStruct mystruct (because MyStruct is 8 bytes);
  5. within above memory space, 4 bytes is used for the reference of the B b object; memory for b object will be allocated in somewhere else when it is instantiated;
  6. within above memory space, 4 bytes is used for the reference of the ArrayList myList; actual memory space for ArrayList myList is allocated in other place and referenced in here as myList;
  7. another 4 or 8 bytes from above memory space is used for object metadata;
  8. …;
  • 1 1 Answer
  • 5 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-16T00:58:35+00:00Added an answer on May 16, 2026 at 12:58 am

    You have the basic idea in place. The actual specifics of this, aside from what you include, is implementation specific. However, for a couple of your points:

    3) The actual string is typically stored in its own memory space, just like any other class. However, since you’re using a string literal in this case, it’ll most likely be in the string intern pool, which is (I believe) stored in the large object heap. For details on string interning, see String.Intern. (If you allocated the string on the fly, instead of using a literal, the string would be stored in the normal managed heap of your application.)

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

Sidebar

Related Questions

class MyClass { public: void setVar(const char *str); private: std::string mStr; int maxLength; //we
Assuming public class MyClass { public int ID {get; set; } public string Name
I have this class: public class Myclass { public int id; public string name;
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
Consider the following: class MyClass { public: int operator ()(int a, int b); };
Say I have this class: class myclass { public int Field1{ get; set; }
Let's say a program like this: class MyClass { public int Numbers; public char
class MyClass { public: void method2() { static int i; ... } }; Will
I have the following pattern: template <int a, int b> class MyClass { public:

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.