By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,987 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,987 IT Pros & Developers. It's quick & easy.

Storing large amounts of object references

P: n/a
Just want to make sure I got this right...

Let's say I have a large array of A objects. Each A object has a
property that contains a reference to a B object. It would be possible
to store the property simply as a string, but I rather make the whole B
object available there. All the A objects may refer to the same B object.

To my understanding, when C# stores the reference to B objects in the A
object property, it just stores an address in memory, not the whole
object itself. So looping through the long list of A objects shouldn't
be slower than if I store the property as a string, right?

Gustaf
May 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
right

--
"Gustaf" <gu*****@algonet.se> schrieb im Newsbeitrag
news:uE**************@TK2MSFTNGP05.phx.gbl...
Just want to make sure I got this right...

Let's say I have a large array of A objects. Each A object has a property
that contains a reference to a B object. It would be possible to store the
property simply as a string, but I rather make the whole B object
available there. All the A objects may refer to the same B object.

To my understanding, when C# stores the reference to B objects in the A
object property, it just stores an address in memory, not the whole object
itself. So looping through the long list of A objects shouldn't be slower
than if I store the property as a string, right?

Gustaf

May 16 '06 #2

P: n/a
Hi,

To my understanding, when C# stores the reference to B objects in the A
object property, it just stores an address in memory, not the whole object
itself. So looping through the long list of A objects shouldn't be slower
than if I store the property as a string, right?


It does store the address in memory or in other words a reference.

May 16 '06 #3

P: n/a
Right... so long as B is declared as a "class" and not as a "struct".
If B is declared as a "struct" then every A will have a separate copy
of B embedded in it. If B is declared as a "class" (which is what you
want) then every A will contain a reference (pointer) to its associated
B, and A's may share one or more B's.

May 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.