Posted By: lethalbyte | Oct 30th, 2005 @ 2:05 AM
page 1 of 1
Comments: 2 | Views: 8551

Am I right in thinking that if I have a large object that takes a lot of memory (DTO objects for example), and I pass it around as arguments between a lot of methods, it's actually only passing about the reference to the object heap?

So it is just as inexpensive to pass around say, a 1Mb object as it is, say, an empty dataset?

Thanks Smiley

Yes, you're right. Only a reference of 4 bytes (8 bytes on 64-bit .NET) is passed as an argument.
Yes, you're only passing a pointer around.

In .NET, things like classes and arrays are "reference types".  That is, if you do something like:

myclass Foo = new myclass();
myclass Bar;
Bar = Foo;

Variable Bar will only contain a reference to Foo, and not a copy of Foo.  Anything you do to Bar will be reflected upon in Foo.
This came back to bite me with arrays once.
page 1 of 1
Comments: 2 | Views: 8551