C++11 classes

Marc Glisse marc.glisse at inria.fr
Wed Nov 16 13:11:30 CET 2011

On Wed, 16 Nov 2011, Hans Aberg wrote:

> On 16 Nov 2011, at 12:23, Marc Glisse wrote:
>>> I drafted some C++11 classes integer etc., using move constructors and assignment operators,
>> Something like that is likely to eventually get standardized in C++, but it may be a while yet.
> It is in the new standard as of August.
>  https://en.wikipedia.org/wiki/C++11

I am talking about an integer class...

>> Note that without lazy initialization, gmp doesn't benefit from moves as much as it could.
> I'm not sure what you have in mind here.

The move constructor still needs to call mp*_init, because it has to leave 
the moved-from object in a usable state, so there is still an allocation.

>>> and then testing with a conversion of the pi program. In the most optimized version, the overhead is less than 10% relative C or C compile as C++,
>> I believe you can get 0 overhead with gmpxx.
> Possibly. The idea here, is to accept some overhead for a considerably simpler syntax. For example, write

Simpler that C, but more complicated than the natural one:
which, with gmpxx from the repository, is equivalent to 
g1*=6*b-1; g1*=6*b-5;

An important goal is that people should be able to write the operations as 
if they were working with int or double and not have to think about how 
the implementation will optimize it.

> Further copying/moving can be done by using a reference count.

That's a different approach. If you use reference counting, move 
operations will bring you less.

Marc Glisse

More information about the gmp-discuss mailing list