Re: Disposable<T>

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Disposable-T-tp11874p11875.html

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
deficiencies.
-- C. A. R. Hoare



-------------------------------------------------------------------------
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
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev