struct containg a reference

J

Jason

Hello

Using c#, I've got a struct, in which I use the NEW keyword and make a
reference to a class, so now I've got a struct on the stack, that contains a
reference to the HEAP.

Is there a way in VS2005 when I'm debugging to see what type of memory is
getting used, stack versus heap?

Thanks
 
J

Jon Skeet [C# MVP]

Using c#, I've got a struct, in which I use the NEW keyword and make a
reference to a class, so now I've got a struct on the stack, that contains a
reference to the HEAP.

Yes. Note that normally when you've got reference type variables, you
still have references on the stack which refer to the heap too.
Is there a way in VS2005 when I'm debugging to see what type of memory is
getting used, stack versus heap?

Not as far as I'm aware - you just need to know where your variables
are.

Jon
 
N

not_a_commie

If it's worth using a struct, then it's probably worth using an index
into an array rather than a reference. It's typical of heap code,
linked lists, and things like that to prefer block allocation but
traditional implementations use pointers for previous / next elements
in the tree. If you're allocating in blocks, just use array indexes
rather than object references.
 
J

Jon Skeet [C# MVP]

not_a_commie said:
If it's worth using a struct, then it's probably worth using an index
into an array rather than a reference.

That entirely depends on the context. Consider KeyValuePair<K,V> which
will *sometimes* contain references and *sometimes* contain values. In
particular, you couldn't just use an index into an array here as you
need to be able to return a KeyValuePair which may be independent of
the Dictionary it comes from.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top