I couldn't find anything related to this question. Suppose I have two
mpfr::mpreal variable (or array of them) is C++ object, it cannot be copied by
memcpy correctly. Use std::copy or loop instead.
memcpy just copies memory blocks bit-by-bit, which works fine for simple POD C-style data structures. C++ objects should be copied by calling the assignment operator so that object can take of memory allocations, etc. by itself.
The size of
mpfr::mpreal is always the same since it just contains pointer to mantissa, which is allocated in heap in different memory location. The
memcpy copies just the pointer, it doesn't reallocate mantissa and thus source and destination mpreals will point to the same mantissa in memory. This is exactly what should be avoided. In turn,
std::copy takes care of this well - by copying every object in a loop using assignment operator of mpreal class (which does the necessary reallocations, etc.)
(I am author of MPFR C++).