Vector types
Marc Glisse
marc.glisse at inria.fr
Fri Sep 21 23:48:39 CEST 2012
On Sat, 22 Sep 2012, Иван Вайгульт wrote:
> I have found answer on my last question :-)
>
>> Expressions which by their nature imply intermediate values, like
>> a=b*c+d*e, still use temporaries though.
>
> That is why I can not use mpz_class.
What this sentence means (never mind if the example is not the best) is
that if you cannot write the C code such that there is no temporary, then
the C++ code won't magically find a way. Even when it is possible, it may
not always find that way. Also, addmul doesn't prevent the use of a
temporary, it just uses an internal temporary, which tends to be cheaper.
> Can you not use a custom allocator with vector<>?
That would be useless. On the other hand, you can use a custom allocator
with gmp. This way you can first malloc a large region of memory, then
initialize the elements of the array in order, and your custom allocator
can give them consecutive parts of your malloc region.
--
Marc Glisse
More information about the gmp-discuss
mailing list