I am having some issues with a memmove in C. As far as I can tell, both locations are valid memory addresses, I am able to print the contents of both memory locations before I perform the memmove, however as soon as I attempt to memmove, the function crashes with a SIGSEGV.
Here is the code in question:
std::cout << page[0] << "\n";
std::cout <<page[1] << "\n" ;
std::cout << cache[index][cache_itr] << "\n";
memmove(cache[index][cache_itr],page,sizeof(float));
//These lines never print.
std::cout << cache[index][cache_itr] << "\n";
std::cout << cache[index][cache_itr] << "\n";
The cache is declared as a float** , and page is a float* which contains a variable size array of floats. The size of the array being an issue is unlikely however, as I cannot even get it to copy over a single float, despite the fact that page undoubtedly contains a float, as evidenced by a valid print out of both page[0] and page[1].
Cache[0] and Cache[1] (index will only ever be 0 or 1, this is also confirmed) are both pointers to a previously calloc-ed cache of float** within a struct object. This can be seen here:
float** cache[2];
cache[0] = queryOb->cache;
cache[1] = cache[0] + sizeOfCache/2;
Where sizeOfCache is initially used to declare how many blocks of size float* we want to calloc for queryOb->cache.
I can't figure out for the life of me why this memmove is producing a sigsegv, I believe it might be to do with the memmove from a float* to a float** however I thought using the two indices on the memmove would cause it to start copying to the correct location.
Any help would be much appreciated!