Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review (concrete complaint)
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2011-03-07 02:29:54


On Sun, 06 Mar 2011 22:28:46 -0800
"Jeffrey Lee Hellrung, Jr." <jhellrung_at_[hidden]> wrote:

>>> This whole argument misses the point of optimizing code that uses a
>>> bigint class. You want to reuse the memory allocated in a bigint
>>> variable over and over instead of reallocating every time.
>>
>> That requires writing at least a minimal memory manager. [...]
>
> I don't think that's what Luke's talking about. He's saying, if x
> has some value, say [x0, x1, x2], and you assign some expression to
> it, you want the result of that expression to directly replace the
> digits [x0, x1, x2], rather than allocating a new block, compute the
> result in this new block, and swap this block in place of the block
> holding [x0, x1, x2].

Okay, I don't see the mechanism, but more on that below.

>>> Whether you make one unneeded allocation or two is a less important
>>> consideration than whether you make one or zero since 2/1 is a lot
>>> smaller than 1/0. If a temporary is generated by the user's code
>>> they have already pessimized their code. I am sorry, but you
>>> cannot avoid allocation with a return by value semantic, only
>>> expression templates allows you to reuse the storage on the left
>>> hand side of the assignment operator. [...]
>>
>> I'm not familiar with a use of expression templates that would allow
>> that. Can you point me to something explaining it?
>
> Expression templates would allow you to tell the compiler, when it
> sees
>
> x = a + b,
>
> to generate code that replaces x's digits with the sum of a's and b's
> digits, one at a time. [...]

How would the expression's code know anything about x, or have access
to its allocated memory? If the template is operator+, you'd have to
pass x to it somehow. If it's not, operator+ would have to allocate
some memory for a temporary, wouldn't it?

> google "c++ expression templates" and/or look at Boost.Proto and
> libraries that use Boost.Proto.

I haven't looked at Boost.Proto yet, but I did look at a couple hits
from Google on the subject in the last couple days. Maybe I'm missing
it, but I didn't see anything that would allow that.

-- 
Chad Nelson
Oak Circle Software, Inc.
*
*
*



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk