Skip to content
Snippets Groups Projects
Commit 288bfbe9 authored by Christoph Sprunk's avatar Christoph Sprunk
Browse files

Changing egsl_alloc_in_context to work like egsl_alloc to avoid memory leaks....

Changing egsl_alloc_in_context to work like egsl_alloc to avoid memory leaks. One could merge these two methods since they do the same only on a different context index...
parent 16ea40dd
No related branches found
No related tags found
No related merge requests found
...@@ -190,12 +190,33 @@ val egsl_alloc(size_t rows, size_t columns) { ...@@ -190,12 +190,33 @@ val egsl_alloc(size_t rows, size_t columns) {
} }
val egsl_alloc_in_context(int context, size_t rows, size_t columns) { val egsl_alloc_in_context(int context, size_t rows, size_t columns) {
egsl_total_allocations++; struct egsl_context*c = egsl_contexts+context;
struct egsl_context *c = egsl_contexts+context;
if(c->nvars>=MAX_VALS) {
fprintf(stderr,"Limit reached, in context %d, nvars is %d\n",context,c->nvars);
egsl_error();
}
int index = c->nvars; int index = c->nvars;
c->vars[index].gsl_m = gsl_matrix_alloc((size_t)rows,(size_t)columns); if(index<c->nallocated) {
c->nvars++; gsl_matrix*m = c->vars[index].gsl_m;
return assemble_val(context,index,c->vars[index].gsl_m); if(m->size1 == rows && m->size2 == columns) {
egsl_cache_hits++;
c->nvars++;
return assemble_val(context,index,c->vars[index].gsl_m);
} else {
gsl_matrix_free(m);
egsl_total_allocations++;
c->vars[index].gsl_m = gsl_matrix_alloc((size_t)rows,(size_t)columns);
c->nvars++;
return assemble_val(context,index,c->vars[index].gsl_m);
}
} else {
egsl_total_allocations++;
c->vars[index].gsl_m = gsl_matrix_alloc((size_t)rows,(size_t)columns);
c->nvars++;
c->nallocated++;
return assemble_val(context,index,c->vars[index].gsl_m);
}
} }
/** Creates a copy of v in the previous context. */ /** Creates a copy of v in the previous context. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment