Objcopy and objmove are used to copy objects from one place to another. Optionally a stride can be supplied.
The functions are equivalent to C's memcpy and memmove. When possible C++ standard library functions are used to implement them
Similar to memcpy and memmove, the difference between objcopy and objmove is that objmove takes account of an overlap of source and destination. In general, objcopy is slighty (but only slighty) faster.
// Create uInt array of 4 elements uInt size=4; int* ia = new int[size]; // Initialize all elements to value 99 objset(ia, 99, size); // Change all odd elements to 66 -> [99 66 99 66] objset(ia+1,66, uInt(5), uInt(2)); // Create another 4-element uInt array int* ia2 = new int[size]; // Copy array ia into array ia2 -> [99 66 99 66] objmove(ia2, ia, size); // Copy the even elements of ia to the odd elements of ia2 // -> [99 99 99 99] objcopy(ia2+1, ia, uInt(size/2), uInt(2), uInt(2));
Setting and copying arrays of a randomly chosen type:
// Create 4-element array of 3-element Block<int> objects uInt size=4; Block<int>* ta = new Block<int>[size]; Block<int> set(3); // Initialize the array -> [[123][123][123][123]] set[0] = 1; set[1] = 2; set[2] = 3; objset(ta, set, size); // Change odd Blocks to [777]-> [[123][777][123][777]] set[0] = set[1] = set[2] = 7; objset(ta + 1, set, uInt(size/2), uInt(2)); // Create another Block<int> array Block<int>* ta2 = new Block<int>[size]; // Copy the even elements of ta to the first elements of ta2 // -> [[123][123]...] objcopy(ta2, ta, uInt(size/2), uInt(1), uInt(2));
The function will call std::copy() when possible. Objmove works correctly if the source and destination overlap in any way.
An exception will be thrown if the source or the destination does not exist (and n is non-zero) or if the strides are non-positive.
/ inline void objmove(const void** to, const void*const *from, uInt n) / { memmove(to, from, n*sizeof(void*)); } / inline void objmove(const char** to, const char*const *from, uInt n) / { memmove(to, from, n*sizeof(char*)); }
/ inline void objmove(void** to, void*const *from, uInt n) / { memmove(to, from, n*sizeof(void*)); } / inline void objmove(char** to, char*const *from, uInt n) / { memmove(to, from, n*sizeof(char*)); }
The non-general function to copy n objects from one place to another. Strides may be specified, i.e. you may copy from every fromStride-th position into every toStride-th one.
Objcopy does not take an overlap of source and destination into account. Objmove should be used if that is an issue.
An exception will be thrown if the source or the destination does not exist or if the strides are non-positive.
/ inline void objcopy(const void** to, const void*const *from, uInt n) / { memcpy(to, from, n*sizeof(void*)); } / inline void objcopy(const char** to, const char*const *from, uInt n) / { memcpy(to, from, n*sizeof(char*)); }
/ inline void objcopy(void** to, void*const *from, uInt n) / { memcpy(to, from, n*sizeof(void*)); } / inline void objcopy(char** to, char*const *from, uInt n) / { memcpy(to, from, n*sizeof(char*)); }
Fill n elements of an array of objects with the given value, optionally with a stride. Note that the fillValue is passed by value.
An exception will be thrown if the destination array does not exist or if the stride is non-positive.