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



> 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
.



Relevant Pages

  • Re: Stack
    ... members of the stack at any given time. ... struct stackelement{ ... struct stackelement item; ... The string you were using was an automatic variable. ...
    (comp.lang.c)
  • Re: how to store list of varying types
    ... When there's a variable-length string, ... typedef struct { ... pointer null, and the second one the CString object. ... then have to finish constructing the packet by copying the two data objects ...
    (microsoft.public.vc.mfc)
  • Re: MVC in C++
    ... Things are now flowing more along the classic MVC lines. ... > struct Observable ... > string version; ... In that case the Controller would trigger a model update *and it* could ...
    (comp.object)
  • A note on personal corruption as a result of using C
    ... Many people in this ng are personally corrupt and use this ng to take ... "A string cannot contain Nuls" Yes it can. ... "A struct is a class" No, ... It appears that no C maven has read a history of mathematics. ...
    (comp.programming)
  • Re: Client - server application C++ - C#
    ... The key word is serialization. ... to XML or to string buffer. ... struct user ...
    (microsoft.public.win32.programmer.networks)

Quantcast