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
...@@ -74,6 +74,18 @@ __attribute__((always_inline)) INLINE void cache_init(struct cache *c, size_t co ...@@ -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); unsigned int sizeBytes = (count + (2 * VEC_SIZE)) * sizeof(float);
int error = 0; 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->x, alignment,sizeBytes);
error += posix_memalign((void **)&c->y, alignment,sizeBytes); error += posix_memalign((void **)&c->y, alignment,sizeBytes);
error += posix_memalign((void **)&c->z, alignment,sizeBytes); error += posix_memalign((void **)&c->z, alignment,sizeBytes);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment