Does memcpy work for large arrays in structures?
I have a structure that has a dynamic array in it. I have defined two of these structures.
I fill the array in the first structure, then use a line like
memcpy(R->v, A->v, A->n*sizeof(double)
where v is the 开发者_StackOverflow中文版array that has been dynamically allocated, and n is the number of entries.
R and A are the same type if that matters.
The problem is, the values are not being properyl copied into R. Any idea why? When I try to debug this in totalview, memcpy goes into a function called "very_huge_loop", but no exception or anything is thrown.
the array is approx 188k doubles in length.
Thanks
It could be memory alignment. Some architectures do not like multi-byte values like double
to start on any arbitrary byte address. When you allocate the array memory, you might want to use a function like memalign()
instead of malloc()
. If you are using new double[n]
then it should already be aligned correctly.
精彩评论