Where are ref types that are members of value types stored?

Discussion in 'ASP .Net' started by Sathyaish, May 22, 2005.

  1. Sathyaish

    Sathyaish Guest

    Structs are value types, strings are ref types. If you have something
    like this:

    struct foo
    {

    System.String str;
    }

    foo TheDayToday;

    then, where's

    TheDayToday.str

    going to be stored?

    (a) The string is going to be stored on the stack;
    (b) The struct is going to be stored on the stack with a 32-bit
    System.IntPtr/System.UInt32 also copied on the stack holding the
    address/reference to the actual string allocated on the heap.
     
    Sathyaish, May 22, 2005
    #1
    1. Advertising

  2. Sathyaish

    Jon Shemitz Guest

    > Structs are value types, strings are ref types. If you have something
    > like this:
    >
    > struct foo
    > {
    >
    > System.String str;
    > }
    >
    > foo TheDayToday;
    >
    > then, where's
    >
    > TheDayToday.str
    >
    > going to be stored?
    >
    > (a) The string is going to be stored on the stack;
    > (b) The struct is going to be stored on the stack with a 32-bit
    > System.IntPtr/System.UInt32 also copied on the stack holding the
    > address/reference to the actual string allocated on the heap.


    (b) is the closest. The struct lives on the stack, and contains a
    String reference, which will be 32-bit on a 32-bit system, and 64-bit
    on a 64-bit system. The difference between "a 32-bit
    System.IntPtr/System.UInt32" and "a String reference" is that the
    system knows that "a String reference" points to a string, and will
    update if the string is moved in GC.

    --

    www.midnightbeach.com
     
    Jon Shemitz, May 22, 2005
    #2
    1. Advertising

  3. Sathyaish

    Sathyaish Guest

    Thank you.
     
    Sathyaish, May 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    341
  2. Replies:
    22
    Views:
    762
    peter koch
    Apr 30, 2008
  3. Replies:
    6
    Views:
    352
    James Kanze
    Apr 29, 2008
  4. Navindra Umanee

    strong ref from weak ref?

    Navindra Umanee, Feb 12, 2005, in forum: Ruby
    Replies:
    2
    Views:
    145
    Navindra Umanee
    Feb 12, 2005
  5. Juha Nieminen
    Replies:
    13
    Views:
    620
    Edek Pienkowski
    Aug 29, 2012
Loading...

Share This Page