snovik | 21 Apr 17:17
Picon

Disposable<T>


Hi,

I am on the team to port ql to c# .net and trying to understand the reasons
behind Disposable<T> class. It looks to me like a tricky memory-saving
excercise and I wonder if it really is or there are other reasons.

would be very grateful.

rgds
s
--

-- 
View this message in context: http://www.nabble.com/Disposable%3CT%3E-tp16807986p16807986.html
Sent from the quantlib-dev mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Luigi Ballabio | 29 Apr 17:55
Picon

Re: Disposable<T>

On Mon, 2008-04-21 at 08:19 -0700, snovik wrote:
> I am on the team to port ql to c# .net and trying to understand the reasons
> behind Disposable<T> class. It looks to me like a tricky memory-saving
> excercise and I wonder if it really is or there are other reasons.

It's not for saving memory---it's for performance. C++ has pass-by-copy
semantics. If we write:

Array operator*(Matrix, Array) {
    ...
    return a;
}

and then

u = M*v;

there will be at least one allocation and one copy of the array
elements, possibly two if the compiler doesn't optimize aggressively.
Disposable<T> removes some of them; not for saving memory, but for
saving time.  If C# returns values by reference, you don't need it in
your port.

Luigi

--

-- 

There are two ways of constructing a software design. One way is to 
make it so simple that there are obviously no deficiencies. And the 
other way is to make it so complicated that there are no obvious 
(Continue reading)

Luigi Ballabio | 29 Apr 21:14
Picon

Re: Disposable<T>


On Apr 29, 2008, at 5:55 PM, Luigi Ballabio wrote:

> On Mon, 2008-04-21 at 08:19 -0700, snovik wrote:
>> I am on the team to port ql to c# .net and trying to understand the 
>> reasons
>> behind Disposable<T> class. It looks to me like a tricky memory-saving
>> excercise and I wonder if it really is or there are other reasons.
>
> It's not for saving memory---it's for performance. C++ has pass-by-copy
> semantics.

Also, the same applies to assignment. In C++, when we write

a = b;

you don't end up with two references (a and b) referring to the same 
instance. You end up with a being a new copy of b.

Luigi

P.S. I almost forgot---good luck with your C# port...

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane