Skip to content

Commit

Permalink
Use OMC allocation in more places over GC
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 4, 2016
1 parent a2943a8 commit 70d6f0e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Compiler/runtime/IOStreamExt_omc.cpp
Expand Up @@ -138,7 +138,7 @@ extern const char* IOStreamExt_appendReversedList(modelica_metatype lst)
tmp = MMC_STRINGDATA(MMC_CAR(lst));
acc += strlen(tmp);
}
res = (char*) GC_malloc(acc+1);
res = (char*) omc_alloc_interface.malloc(acc+1);
res_head = res;
res += acc;
res[0] = '\0';
Expand All @@ -165,7 +165,7 @@ extern void IOStreamExt_printReversedList(modelica_metatype lst, int whereToPrin
case 2: f = stderr; break;
default: MMC_THROW();
}
strs = (const char**) GC_malloc(sizeof(const char*)*lstLen);
strs = (const char**) omc_alloc_interface.malloc(sizeof(const char*)*lstLen);

for (i=0; i<lstLen ; i++, lst = MMC_CDR(lst)) {
strs[i] = MMC_STRINGDATA(MMC_CAR(lst));
Expand Down
18 changes: 9 additions & 9 deletions Compiler/runtime/SimulationResults.c
Expand Up @@ -428,9 +428,9 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
int numUniqueParam = 1;
int longestName = 0;
int longestDesc = 0;
ModelicaMatVariable_t **mat_var = GC_malloc(numToFilter*sizeof(ModelicaMatVariable_t*));
int *indexes = (int*) GC_malloc(simresglob.matReader.nvar*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
int *parameter_indexes = (int*) GC_malloc(simresglob.matReader.nparam*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
ModelicaMatVariable_t **mat_var = omc_alloc_interface.malloc(numToFilter*sizeof(ModelicaMatVariable_t*));
int *indexes = (int*) omc_alloc_interface.malloc(simresglob.matReader.nvar*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
int *parameter_indexes = (int*) omc_alloc_interface.malloc(simresglob.matReader.nparam*sizeof(int)); /* Need it to be zeros; note that the actual number of indexes is smaller */
int *indexesToOutput = NULL;
int *parameter_indexesToOutput = NULL;
FILE *fout = NULL;
Expand All @@ -441,7 +441,7 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
parameter_indexes[0] = 1; /* time */
omc_matlab4_read_all_vals(&simresglob.matReader);
if (endsWith(outFile,".csv")) {
double **vals = GC_malloc(sizeof(double*)*numToFilter);
double **vals = omc_alloc_interface.malloc(sizeof(double*)*numToFilter);
FILE *fout = NULL;
for (i=0; i<numToFilter; i++) {
const char *var = MMC_STRINGDATA(MMC_CAR(vars));
Expand Down Expand Up @@ -497,8 +497,8 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
longestDesc = intMax(longestDesc, strlen(mat_var[i]->descr));
}
/* Create the list of variable indexes to output */
indexesToOutput = GC_malloc_atomic(numUnique * sizeof(int));
parameter_indexesToOutput = GC_malloc_atomic(numUniqueParam * sizeof(int));
indexesToOutput = omc_alloc_interface.malloc_atomic(numUnique * sizeof(int));
parameter_indexesToOutput = omc_alloc_interface.malloc_atomic(numUniqueParam * sizeof(int));
j=0;
for (i=0; i<simresglob.matReader.nvar; i++) {
if (indexes[i]) {
Expand Down Expand Up @@ -527,7 +527,7 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
return failedToWriteToFile(outFile);
}

tmp = GC_malloc(numToFilter*longestName);
tmp = omc_alloc_interface.malloc(numToFilter*longestName);
for (i=0; i<numToFilter; i++) {
int len = strlen(mat_var[i]->name);
for (j=0; j<len; j++) {
Expand All @@ -543,7 +543,7 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
return failedToWriteToFile(outFile);
}

tmp = GC_malloc(numToFilter*longestDesc);
tmp = omc_alloc_interface.malloc(numToFilter*longestDesc);
for (i=0; i<numToFilter; i++) {
int len = strlen(mat_var[i]->descr);
for (j=0; j<len; j++) {
Expand Down Expand Up @@ -638,7 +638,7 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
if (numberOfIntervals) {
omc_matlab4_read_all_vals(&simresglob.matReader);
nrows = numberOfIntervals+1;
vals = GC_malloc_atomic(sizeof(double)*nrows);
vals = omc_alloc_interface.malloc_atomic(sizeof(double)*nrows);
for (j=0; j<=numberOfIntervals; j++) {
double t = j==numberOfIntervals ? stop : start + (stop-start)*((double)j)/numberOfIntervals;
ModelicaMatVariable_t var = {0};
Expand Down
10 changes: 5 additions & 5 deletions Compiler/runtime/SimulationResultsCmp.c
Expand Up @@ -79,7 +79,7 @@ static char ** getVars(void *vars, unsigned int* nvars)
}

/* Allocate a new string array to contain the variable names. */
cmpvars = (char**)GC_malloc(sizeof(char*)*(ncmpvars));
cmpvars = (char**)omc_alloc_interface.malloc(sizeof(char*)*(ncmpvars));

/* Copy the variable names from the MetaModelica list to the string array. */
for(; MMC_NILHDR != MMC_GETHDR(vars); vars = MMC_CDR(vars)) {
Expand Down Expand Up @@ -552,7 +552,7 @@ void* SimulationResultsCmp_compareResults(int isResultCmp, int runningTestsuite,
/* open files */
/* fprintf(stderr, "Open File %s\n", filename); */
if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(filename,&simresglob_c)) {
char *str = (char*) GC_malloc(25+strlen(filename));
char *str = (char*) omc_alloc_interface.malloc(25+strlen(filename));
void *res = NULL;
*str = 0;
strcat(strcat(str,"Error opening file: "), filename);
Expand All @@ -562,7 +562,7 @@ void* SimulationResultsCmp_compareResults(int isResultCmp, int runningTestsuite,
}
/* fprintf(stderr, "Open File %s\n", reffilename); */
if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(reffilename,&simresglob_ref)) {
char *str = (char*) GC_malloc(35+strlen(reffilename));
char *str = (char*) omc_alloc_interface.malloc(35+strlen(reffilename));
void *res = NULL;
*str = 0;
strcat(strcat(str,"Error opening reference file: "), reffilename);
Expand Down Expand Up @@ -604,7 +604,7 @@ void* SimulationResultsCmp_compareResults(int isResultCmp, int runningTestsuite,
if (timeref.n==0) {
return mmc_mk_cons(mmc_mk_scon("Error get ref time!"),mmc_mk_nil());
}
cmpdiffvars = (char**)GC_malloc(sizeof(char*)*(ncmpvars));
cmpdiffvars = (char**)omc_alloc_interface.malloc(sizeof(char*)*(ncmpvars));
/* check if time is larger or less reftime */
res = mmc_mk_nil();
if (fabs(time.data[time.n-1]-timeref.data[timeref.n-1]) > reltol*fabs(timeref.data[timeref.n-1])) {
Expand All @@ -628,7 +628,7 @@ void* SimulationResultsCmp_compareResults(int isResultCmp, int runningTestsuite,
free(var1);
var1 = NULL;
}
var1 = (char*) GC_malloc(len+10);
var1 = (char*) omc_alloc_interface.malloc(len+10);
k = 0;
for (j=0;j<len;j++) {
if (var[j] !='\"' ) {
Expand Down
46 changes: 23 additions & 23 deletions Compiler/runtime/SimulationResultsCmpTubes.c
Expand Up @@ -201,7 +201,7 @@ static void generateLowTube(privates *priv, double *x, double *y)

static privates* skipCalculateTubes(double *x, double *y, size_t length)
{
privates *priv = (privates*) GC_malloc(sizeof(privates));
privates *priv = (privates*) omc_alloc_interface.malloc(sizeof(privates));

/* set tStart and tStop */
priv->length = length;
Expand All @@ -211,8 +211,8 @@ static privates* skipCalculateTubes(double *x, double *y, size_t length)
priv->xMinStep = ((priv->tStop - priv->tStart) + fabs(priv->tStart)) * priv->xRelEps;
priv->countLow = length;
priv->countHigh = length;
priv->yHigh = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->yLow = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->yHigh = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->yLow = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
memcpy(priv->yHigh, y, length * sizeof(double));
memcpy(priv->yLow, y, length * sizeof(double));
return priv;
Expand All @@ -221,7 +221,7 @@ static privates* skipCalculateTubes(double *x, double *y, size_t length)
/* This method generates tubes around a given curve */
static privates* calculateTubes(double *x, double *y, size_t length, double r)
{
privates *priv = (privates*) GC_malloc(sizeof(privates));
privates *priv = (privates*) omc_alloc_interface.malloc(sizeof(privates));
int i;
/* set tStart and tStop */
priv->length = length;
Expand All @@ -233,18 +233,18 @@ static privates* calculateTubes(double *x, double *y, size_t length, double r)
priv->countHigh = 0;

/* Initialize lists (upper tube) */
priv->mh = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->i0h = (int*)GC_malloc_atomic(sizeof(int)*length);
priv->i1h = (int*)GC_malloc_atomic(sizeof(int)*length);
priv->mh = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->i0h = (int*)omc_alloc_interface.malloc_atomic(sizeof(int)*length);
priv->i1h = (int*)omc_alloc_interface.malloc_atomic(sizeof(int)*length);
/* Initialize lists (lower tube) */
priv->ml = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->i0l = (int*)GC_malloc_atomic(sizeof(int)*length);
priv->i1l = (int*)GC_malloc_atomic(sizeof(int)*length);
priv->ml = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->i0l = (int*)omc_alloc_interface.malloc_atomic(sizeof(int)*length);
priv->i1l = (int*)omc_alloc_interface.malloc_atomic(sizeof(int)*length);

priv->xHigh = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->xLow = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->yHigh = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->yLow = (double*)GC_malloc_atomic(sizeof(double)*length);
priv->xHigh = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->xLow = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->yHigh = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);
priv->yLow = (double*)omc_alloc_interface.malloc_atomic(sizeof(double)*length);

/* calculate the tubes delta */
priv->delta = r * (priv->tStop - priv->tStart);
Expand Down Expand Up @@ -381,7 +381,7 @@ static double* calibrateValues(double* sourceTimeLine, double* targetTimeLine, d
}

n = *nsource;
interpolatedValues = (double*) GC_malloc_atomic(sizeof(double)*n);
interpolatedValues = (double*) omc_alloc_interface.malloc_atomic(sizeof(double)*n);

j = 1;
for (i = 0; i < n; i++) {
Expand Down Expand Up @@ -449,8 +449,8 @@ static addTargetEventTimesRes addTargetEventTimes(double* sourceTimeLine, double
return res;
}
res.size = nsource+count;
res.values = GC_malloc_atomic(sizeof(double)*res.size);
res.time = GC_malloc_atomic(sizeof(double)*res.size);
res.values = omc_alloc_interface.malloc_atomic(sizeof(double)*res.size);
res.time = omc_alloc_interface.malloc_atomic(sizeof(double)*res.size);
i=0;
count=0;
j=findNextEvent(1,targetTimeLine,ntarget,xabstol);
Expand Down Expand Up @@ -491,8 +491,8 @@ static addTargetEventTimesRes mergeTimelines(addTargetEventTimesRes ref, addTarg
int i=0,j=0,count=0;
addTargetEventTimesRes res;
res.size = ref.size + actual.size;
res.values = GC_malloc_atomic(sizeof(double)*res.size);
res.time = GC_malloc_atomic(sizeof(double)*res.size);
res.values = omc_alloc_interface.malloc_atomic(sizeof(double)*res.size);
res.time = omc_alloc_interface.malloc_atomic(sizeof(double)*res.size);
res.values[count] = ref.values[0];
res.time[count++] = ref.time[0];
for (i=1; i<ref.size; i++) {
Expand Down Expand Up @@ -526,8 +526,8 @@ static addTargetEventTimesRes removeUneventfulPoints(addTargetEventTimesRes in,
{
int i;
addTargetEventTimesRes res;
res.values = (double*) GC_malloc_atomic(in.size * sizeof(double));
res.time = (double*) GC_malloc_atomic(in.size * sizeof(double));
res.values = (double*) omc_alloc_interface.malloc_atomic(in.size * sizeof(double));
res.time = (double*) omc_alloc_interface.malloc_atomic(in.size * sizeof(double));

do {
int iter = 0;
Expand Down Expand Up @@ -603,7 +603,7 @@ static void assertMonotonic(addTargetEventTimesRes series)
/* Return NULL if there were no errors */
static double* validate(int n, addTargetEventTimesRes ref, double *low, double *high, double *calibrated_values, double reltol, double abstol, double xabstol)
{
double *error = GC_malloc_atomic(n * sizeof(double));
double *error = omc_alloc_interface.malloc_atomic(n * sizeof(double));
int isdifferent = 0;
int i,lastStepError = 1;
for (i=0; i<n; i++) {
Expand Down Expand Up @@ -731,7 +731,7 @@ static unsigned int cmpDataTubes(int isResultCmp, char* varname, DataField *time
rangeDelta
);
} else if (!isResultCmp && (error || keepEqualResults)) {
fname = (char*) GC_malloc_atomic(25 + strlen(prefix) + strlen(varname));
fname = (char*) omc_alloc_interface.malloc_atomic(25 + strlen(prefix) + strlen(varname));
sprintf(fname, "%s.%s.csv", prefix, varname);
fout = fopen(fname,"w");
}
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/systemimplmisc.cpp
Expand Up @@ -36,7 +36,7 @@ extern "C" {
FindAndReplace(str,string(search_str),string(replace_str));

len = strlen(str.c_str());
char* res = (char *)GC_malloc_atomic(len + 1);
char* res = (char *)omc_alloc_interface.malloc_atomic(len + 1);
strcpy(res, str.c_str());
res[len] = '\0';
return res;
Expand Down

0 comments on commit 70d6f0e

Please sign in to comment.