Skip to content
Snippets Groups Projects
Commit 19d92fc4 authored by James Willis's avatar James Willis
Browse files

Free allocated memory if the cache needs to be re-allocated.

parent 55e67f34
No related branches found
No related tags found
1 merge request!287Particle caching
......@@ -74,6 +74,18 @@ __attribute__((always_inline)) INLINE void cache_init(struct cache *c, size_t co
unsigned int sizeBytes = (count + (2 * VEC_SIZE)) * sizeof(float);
int error = 0;
/* Free memory if cache has already been allocated. */
if (c->count > 0) {
free(c->x);
free(c->y);
free(c->z);
free(c->m);
free(c->vx);
free(c->vy);
free(c->vz);
free(c->h);
}
error += posix_memalign((void **)&c->x, alignment,sizeBytes);
error += posix_memalign((void **)&c->y, alignment,sizeBytes);
error += posix_memalign((void **)&c->z, alignment,sizeBytes);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment