C++ Programming
08-12-2009, 08:42 PM
Hi all,
I'm in the process of writing my own Matrix Library, and have been using the standard way to copy things around, i.e. if i have a pointer to a bunch of doubles, say
T * my_doubles = new T[64];
representing an 8 by 8 array, then if i want a copy constructor of a class to duplicate this then i just issue the following code in the copy constructor:
for(unsigned int count = 0; count < 64; count++)
new_doubles[count] = my_doubles[count];
however, i have been reading around on the net that there are faster ways to copy memory, mainly using memcpy. i have also learned that some people are against the use of this because the compiler optimizes code such as that above to be the most efficient.
so what's it to be?... regarding SPEED, is it really best to let the compiler optimize, or use memcpy, or some other method?... and if so what are these methods?
Many thanks,
Paul
I'm in the process of writing my own Matrix Library, and have been using the standard way to copy things around, i.e. if i have a pointer to a bunch of doubles, say
T * my_doubles = new T[64];
representing an 8 by 8 array, then if i want a copy constructor of a class to duplicate this then i just issue the following code in the copy constructor:
for(unsigned int count = 0; count < 64; count++)
new_doubles[count] = my_doubles[count];
however, i have been reading around on the net that there are faster ways to copy memory, mainly using memcpy. i have also learned that some people are against the use of this because the compiler optimizes code such as that above to be the most efficient.
so what's it to be?... regarding SPEED, is it really best to let the compiler optimize, or use memcpy, or some other method?... and if so what are these methods?
Many thanks,
Paul