C++11 classes

Hans Aberg haberg-1 at telia.com
Wed Nov 16 15:07:17 CET 2011


On 16 Nov 2011, at 13:11, 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…

OK. But not anyway soon.

>>> 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.

The move constructor just moves the data, and sets the original to a state which is not affected by delete. The other constructors do the 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:
> g1=g1*(6*b-1)*(6*b-5)
> which, with gmpxx from the repository, is equivalent to g1*=6*b-1; g1*=6*b-5;

I haven't tried this one. It might be of interest of converting the pi program for comparison.

> 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.

My interest came from creating types for another language.

>> 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.


With a GC, like the Hans Boehm one, one might not need to have move constructors at all. A copy constructor may just copy over a pointer, keeping in mind that objects are references.

Hans




More information about the gmp-discuss mailing list