diff --git a/src/spicelib/devices/bsim3/b3dest.c b/src/spicelib/devices/bsim3/b3dest.c index c40be1abe..27af1ba3b 100644 --- a/src/spicelib/devices/bsim3/b3dest.c +++ b/src/spicelib/devices/bsim3/b3dest.c @@ -18,6 +18,11 @@ BSIM3destroy(GENmodel **inModel) { BSIM3model *mod = *(BSIM3model**) inModel; + #ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM3InstanceArray); + #endif + while (mod) { BSIM3model *next_mod = mod->BSIM3nextModel; BSIM3instance *inst = mod->BSIM3instances; @@ -37,11 +42,6 @@ BSIM3destroy(GENmodel **inModel) inst = next_inst; } -#ifdef USE_OMP - /* free just once for all models */ - FREE(mod->BSIM3InstanceArray); -#endif - /* mod->BSIM3modName to be freed in INPtabEnd() */ FREE(mod->BSIM3version); FREE(mod); diff --git a/src/spicelib/devices/bsim3/b3set.c b/src/spicelib/devices/bsim3/b3set.c index 9963b2f6a..33cb88f98 100644 --- a/src/spicelib/devices/bsim3/b3set.c +++ b/src/spicelib/devices/bsim3/b3set.c @@ -41,6 +41,12 @@ CKTnode *tmp; CKTnode *tmpNode; IFuid tmpName; +#ifdef USE_OMP +int idx, InstCount; +BSIM3instance **InstArray; +#endif + + /* loop through all the BSIM3 device models */ for( ; model != NULL; model = model->BSIM3nextModel ) { @@ -1079,24 +1085,34 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ } } #ifdef USE_OMP + InstCount = 0; + model = (BSIM3model*)inModel; + /* loop through all the BSIM3 device models + to count the number of instances */ - for (model = (BSIM3model*)inModel; model; model = model->BSIM3nextModel ) + for( ; model != NULL; model = model->BSIM3nextModel ) { - BSIM3instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM3instances; here; here = here->BSIM3nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM3instances; here != NULL ; + here=here->BSIM3nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM3instance*, InstCount); + model = (BSIM3model*)inModel; + idx = 0; + for( ; model != NULL; model = model->BSIM3nextModel ) + { + /* loop through all the instances of the model */ + for (here = model->BSIM3instances; here != NULL ; + here=here->BSIM3nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM3InstCount = idx; - - InstArray = TMALLOC(BSIM3instance*, idx); - - idx = 0; - for (here = model->BSIM3instances; here; here = here->BSIM3nextInstance) - InstArray[idx++] = here; - + } + /* set the array pointer and instance count into each model */ + model->BSIM3InstCount = InstCount; model->BSIM3InstanceArray = InstArray; } diff --git a/src/spicelib/devices/bsim3v32/b3v32dest.c b/src/spicelib/devices/bsim3v32/b3v32dest.c index eb8b1480a..b20736ffc 100644 --- a/src/spicelib/devices/bsim3v32/b3v32dest.c +++ b/src/spicelib/devices/bsim3v32/b3v32dest.c @@ -19,6 +19,11 @@ BSIM3v32destroy (GENmodel **inModel) { BSIM3v32model *mod = *(BSIM3v32model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM3v32InstanceArray); +#endif + while (mod) { BSIM3v32model *next_mod = mod->BSIM3v32nextModel; BSIM3v32instance *inst = mod->BSIM3v32instances; @@ -35,9 +40,6 @@ BSIM3v32destroy (GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->BSIM3v32InstanceArray); -#endif FREE(mod->BSIM3v32version); FREE(mod); mod = next_mod; diff --git a/src/spicelib/devices/bsim3v32/b3v32set.c b/src/spicelib/devices/bsim3v32/b3v32set.c index 58d030044..991cb01ed 100644 --- a/src/spicelib/devices/bsim3v32/b3v32set.c +++ b/src/spicelib/devices/bsim3v32/b3v32set.c @@ -38,6 +38,11 @@ CKTnode *tmp; CKTnode *tmpNode; IFuid tmpName; +#ifdef USE_OMP +int idx, InstCount; +BSIM3v32instance **InstArray; +#endif + /* loop through all the BSIM3v32 device models */ for( ; model != NULL; model = model->BSIM3v32nextModel ) { @@ -1091,26 +1096,35 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ } } - #ifdef USE_OMP + InstCount = 0; + model = (BSIM3v32model*)inModel; + /* loop through all the BSIM3 device models + to count the number of instances */ - for (model = (BSIM3v32model*)inModel; model; model = model->BSIM3v32nextModel) + for (; model != NULL; model = model->BSIM3v32nextModel) { - BSIM3v32instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM3v32instances; here; here = here->BSIM3v32nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM3v32instances; here != NULL; + here = here->BSIM3v32nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM3v32instance*, InstCount); + model = (BSIM3v32model*)inModel; + idx = 0; + for (; model != NULL; model = model->BSIM3v32nextModel) + { + /* loop through all the instances of the model */ + for (here = model->BSIM3v32instances; here != NULL; + here = here->BSIM3v32nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM3v32InstCount = idx; - - InstArray = TMALLOC(BSIM3v32instance*, idx); - - idx = 0; - for (here = model->BSIM3v32instances; here; here = here->BSIM3v32nextInstance) - InstArray[idx++] = here; - + } + /* set the array pointer and instance count into each model */ + model->BSIM3v32InstCount = InstCount; model->BSIM3v32InstanceArray = InstArray; } diff --git a/src/spicelib/devices/bsim4/b4dest.c b/src/spicelib/devices/bsim4/b4dest.c index 3f288c749..ca8fab3fa 100644 --- a/src/spicelib/devices/bsim4/b4dest.c +++ b/src/spicelib/devices/bsim4/b4dest.c @@ -20,6 +20,11 @@ BSIM4destroy(GENmodel **inModel) { BSIM4model *mod = *(BSIM4model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM4InstanceArray); +#endif + while (mod) { BSIM4model *next_mod = mod->BSIM4nextModel; BSIM4instance *inst = mod->BSIM4instances; @@ -36,9 +41,6 @@ BSIM4destroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->BSIM4InstanceArray); -#endif FREE(mod->BSIM4version); FREE(mod); mod = next_mod; diff --git a/src/spicelib/devices/bsim4/b4set.c b/src/spicelib/devices/bsim4/b4set.c index 1bfb4cdbd..fa445937d 100644 --- a/src/spicelib/devices/bsim4/b4set.c +++ b/src/spicelib/devices/bsim4/b4set.c @@ -60,6 +60,11 @@ int noiseAnalGiven = 0, createNode; /* Criteria for new node creation */ double Rtot, DMCGeff, DMCIeff, DMDGeff; JOB *job; +#ifdef USE_OMP +int idx, InstCount; +BSIM4instance **InstArray; +#endif + /* Search for a noise analysis request */ for (job = ((TSKtask *)ft_curckt->ci_curTask)->jobs;job;job = job->JOBnextJob) { if(strcmp(job->JOBname,"Noise Analysis")==0) { @@ -2652,24 +2657,35 @@ do { if((here->ptr = SMPmakeElt(matrix,here->first,here->second))==(double *)NUL } #ifdef USE_OMP - for (model = (BSIM4model*)inModel; model; model = model->BSIM4nextModel) + InstCount = 0; + model = (BSIM4model*)inModel; + /* loop through all the BSIM4 device models + to count the number of instances */ + + for( ; model != NULL; model = model->BSIM4nextModel ) { - BSIM4instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM4instances; here; here = here->BSIM4nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM4instances; here != NULL ; + here=here->BSIM4nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM4instance*, InstCount); + model = (BSIM4model*)inModel; + idx = 0; + for( ; model != NULL; model = model->BSIM4nextModel ) + { + /* loop through all the instances of the model */ + for (here = model->BSIM4instances; here != NULL ; + here=here->BSIM4nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM4InstCount = idx; - - InstArray = TMALLOC(BSIM4instance*, idx); - - idx = 0; - for (here = model->BSIM4instances; here; here = here->BSIM4nextInstance) - InstArray[idx++] = here; - - model->BSIM4InstanceArray = InstArray; + } + /* set the array pointer and instance count into each model */ + model->BSIM4InstCount = InstCount; + model->BSIM4InstanceArray = InstArray; } #endif diff --git a/src/spicelib/devices/bsim4v5/b4v5dest.c b/src/spicelib/devices/bsim4v5/b4v5dest.c index 00911df15..876062d46 100644 --- a/src/spicelib/devices/bsim4v5/b4v5dest.c +++ b/src/spicelib/devices/bsim4v5/b4v5dest.c @@ -18,6 +18,11 @@ BSIM4v5destroy(GENmodel **inModel) { BSIM4v5model *mod = *(BSIM4v5model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM4v5InstanceArray); +#endif + while (mod) { BSIM4v5model *next_mod = mod->BSIM4v5nextModel; BSIM4v5instance *inst = mod->BSIM4v5instances; @@ -34,9 +39,6 @@ BSIM4v5destroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->BSIM4v5InstanceArray); -#endif FREE(mod->BSIM4v5version); FREE(mod); mod = next_mod; diff --git a/src/spicelib/devices/bsim4v5/b4v5set.c b/src/spicelib/devices/bsim4v5/b4v5set.c index 903a08749..a803aa278 100644 --- a/src/spicelib/devices/bsim4v5/b4v5set.c +++ b/src/spicelib/devices/bsim4v5/b4v5set.c @@ -52,6 +52,11 @@ int noiseAnalGiven = 0, createNode; /* Criteria for new node creation */ double Rtot, DMCGeff, DMCIeff, DMDGeff; JOB *job; +#ifdef USE_OMP +int idx, InstCount; +BSIM4v5instance **InstArray; +#endif + /* Search for a noise analysis request */ for (job = ft_curckt->ci_curTask->jobs; job; job = job->JOBnextJob) { if(strcmp(job->JOBname,"Noise Analysis")==0) { @@ -2078,23 +2083,34 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ } #ifdef USE_OMP - for (model = (BSIM4v5model*)inModel; model; model = model->BSIM4v5nextModel) + InstCount = 0; + model = (BSIM4v5model*)inModel; + /* loop through all the BSIM4v6 device models + to count the number of instances */ + + for (; model != NULL; model = model->BSIM4v5nextModel) { - BSIM4v5instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM4v5instances; here; here = here->BSIM4v5nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM4v5instances; here != NULL; + here = here->BSIM4v5nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM4v5instance*, InstCount); + model = (BSIM4v5model*)inModel; + idx = 0; + for (; model != NULL; model = model->BSIM4v5nextModel) + { + /* loop through all the instances of the model */ + for (here = model->BSIM4v5instances; here != NULL; + here = here->BSIM4v5nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM4v5InstCount = idx; - - InstArray = TMALLOC(BSIM4v5instance*, idx); - - idx = 0; - for (here = model->BSIM4v5instances; here; here = here->BSIM4v5nextInstance) - InstArray[idx++] = here; - + } + /* set the array pointer and instance count into each model */ + model->BSIM4v5InstCount = InstCount; model->BSIM4v5InstanceArray = InstArray; } #endif diff --git a/src/spicelib/devices/bsim4v6/b4v6dest.c b/src/spicelib/devices/bsim4v6/b4v6dest.c index a146df3a4..0d1c5e64a 100644 --- a/src/spicelib/devices/bsim4v6/b4v6dest.c +++ b/src/spicelib/devices/bsim4v6/b4v6dest.c @@ -20,6 +20,11 @@ BSIM4v6destroy(GENmodel **inModel) { BSIM4v6model *mod = *(BSIM4v6model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM4v6InstanceArray); +#endif + while (mod) { BSIM4v6model *next_mod = mod->BSIM4v6nextModel; BSIM4v6instance *inst = mod->BSIM4v6instances; @@ -36,9 +41,6 @@ BSIM4v6destroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->BSIM4v6InstanceArray); -#endif FREE(mod->BSIM4v6version); FREE(mod); mod = next_mod; diff --git a/src/spicelib/devices/bsim4v6/b4v6set.c b/src/spicelib/devices/bsim4v6/b4v6set.c index ab71184be..f009e7c91 100644 --- a/src/spicelib/devices/bsim4v6/b4v6set.c +++ b/src/spicelib/devices/bsim4v6/b4v6set.c @@ -59,6 +59,11 @@ double Rtot, DMCGeff, DMCIeff, DMDGeff; JOB *job; +#ifdef USE_OMP +int idx, InstCount; +BSIM4v6instance **InstArray; +#endif + /* Search for a noise analysis request */ for (job = ft_curckt->ci_curTask->jobs; job; job = job->JOBnextJob) { if(strcmp(job->JOBname,"Noise Analysis")==0) { @@ -2413,24 +2418,35 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ } /* end of loop through all the BSIM4v6 device models */ #ifdef USE_OMP - for (model = (BSIM4v6model*)inModel; model; model = model->BSIM4v6nextModel) + InstCount = 0; + model = (BSIM4v6model*)inModel; + /* loop through all the BSIM4v6 device models + to count the number of instances */ + + for( ; model != NULL; model = model->BSIM4v6nextModel ) { - BSIM4v6instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM4v6instances; here; here = here->BSIM4v6nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM4v6instances; here != NULL ; + here=here->BSIM4v6nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM4v6instance*, InstCount); + model = (BSIM4v6model*)inModel; + idx = 0; + for( ; model != NULL; model = model->BSIM4v6nextModel ) + { + /* loop through all the instances of the model */ + for (here = model->BSIM4v6instances; here != NULL ; + here=here->BSIM4v6nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM4v6InstCount = idx; - - InstArray = TMALLOC(BSIM4v6instance*, idx); - - idx = 0; - for (here = model->BSIM4v6instances; here; here = here->BSIM4v6nextInstance) - InstArray[idx++] = here; - - model->BSIM4v6InstanceArray = InstArray; + } + /* set the array pointer and instance count into each model */ + model->BSIM4v6InstCount = InstCount; + model->BSIM4v6InstanceArray = InstArray; } #endif diff --git a/src/spicelib/devices/bsim4v7/b4v7dest.c b/src/spicelib/devices/bsim4v7/b4v7dest.c index 7125ba7f2..206708b27 100644 --- a/src/spicelib/devices/bsim4v7/b4v7dest.c +++ b/src/spicelib/devices/bsim4v7/b4v7dest.c @@ -20,6 +20,11 @@ BSIM4v7destroy(GENmodel **inModel) { BSIM4v7model *mod = *(BSIM4v7model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->BSIM4v7InstanceArray); +#endif + while (mod) { BSIM4v7model *next_mod = mod->BSIM4v7nextModel; BSIM4v7instance *inst = mod->BSIM4v7instances; @@ -36,9 +41,6 @@ BSIM4v7destroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->BSIM4v7InstanceArray); -#endif /* mod->BSIM4v7modName to be freed in INPtabEnd() */ FREE(mod->BSIM4v7version); FREE(mod); diff --git a/src/spicelib/devices/bsim4v7/b4v7set.c b/src/spicelib/devices/bsim4v7/b4v7set.c index c97999d97..00d0ea20d 100644 --- a/src/spicelib/devices/bsim4v7/b4v7set.c +++ b/src/spicelib/devices/bsim4v7/b4v7set.c @@ -58,6 +58,11 @@ int noiseAnalGiven = 0, createNode; /* Criteria for new node creation */ double Rtot, DMCGeff, DMCIeff, DMDGeff; JOB *job; +#ifdef USE_OMP +int idx, InstCount; +BSIM4v7instance **InstArray; +#endif + /* Search for a noise analysis request */ for (job = ((TSKtask *)ft_curckt->ci_curTask)->jobs;job;job = job->JOBnextJob) { if(strcmp(job->JOBname,"Noise Analysis")==0) { @@ -2568,24 +2573,35 @@ do { if((here->ptr = SMPmakeElt(matrix,here->first,here->second))==(double *)NUL } #ifdef USE_OMP - for (model = (BSIM4v7model*)inModel; model; model = model->BSIM4v7nextModel) + InstCount = 0; + model = (BSIM4v7model*)inModel; + /* loop through all the BSIM4v7 device models + to count the number of instances */ + + for( ; model != NULL; model = model->BSIM4v7nextModel ) { - BSIM4v7instance **InstArray; - int idx; - - idx = 0; - for (here = model->BSIM4v7instances; here; here = here->BSIM4v7nextInstance) + /* loop through all the instances of the model */ + for (here = model->BSIM4v7instances; here != NULL ; + here=here->BSIM4v7nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(BSIM4v7instance*, InstCount); + model = (BSIM4v7model*)inModel; + idx = 0; + for( ; model != NULL; model = model->BSIM4v7nextModel ) + { + /* loop through all the instances of the model */ + for (here = model->BSIM4v7instances; here != NULL ; + here=here->BSIM4v7nextInstance) + { + InstArray[idx] = here; idx++; - - model->BSIM4v7InstCount = idx; - - InstArray = TMALLOC(BSIM4v7instance*, idx); - - idx = 0; - for (here = model->BSIM4v7instances; here; here = here->BSIM4v7nextInstance) - InstArray[idx++] = here; - - model->BSIM4v7InstanceArray = InstArray; + } + /* set the array pointer and instance count into each model */ + model->BSIM4v7InstCount = InstCount; + model->BSIM4v7InstanceArray = InstArray; } #endif diff --git a/src/spicelib/devices/bsimsoi/b4soidest.c b/src/spicelib/devices/bsimsoi/b4soidest.c index f6f6ed0f8..c66c177ce 100644 --- a/src/spicelib/devices/bsimsoi/b4soidest.c +++ b/src/spicelib/devices/bsimsoi/b4soidest.c @@ -32,9 +32,6 @@ B4SOIdestroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->B4SOIInstanceArray); -#endif FREE(mod); mod = next_mod; } diff --git a/src/spicelib/devices/bsimsoi/b4soiset.c b/src/spicelib/devices/bsimsoi/b4soiset.c index 804c79f93..e13d33960 100644 --- a/src/spicelib/devices/bsimsoi/b4soiset.c +++ b/src/spicelib/devices/bsimsoi/b4soiset.c @@ -53,6 +53,11 @@ double Cboxt; /* v3.2 */ double Vbs0t, Qsi; +#ifdef USE_OMP +int idx, InstCount; +B4SOIinstance **InstArray; +#endif + /* loop through all the B4SOI device models */ for( ; model != NULL; model = model->B4SOInextModel ) { @@ -2701,24 +2706,35 @@ do { if((here->ptr = SMPmakeElt(matrix,here->first,here->second))==(double *)NUL } #ifdef USE_OMP - for (model = (B4SOImodel*)inModel; model; model = model->B4SOInextModel) + InstCount = 0; + model = (B4SOImodel*)inModel; + /* loop through all the B4SOI device models + to count the number of instances */ + + for( ; model != NULL; model = model->B4SOInextModel ) { - B4SOIinstance **InstArray; - int idx; - - idx = 0; - for (here = model->B4SOIinstances; here; here = here->B4SOInextInstance) + /* loop through all the instances of the model */ + for (here = model->B4SOIinstances; here != NULL ; + here=here->B4SOInextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(B4SOIinstance*, InstCount); + model = (B4SOImodel*)inModel; + idx = 0; + for( ; model != NULL; model = model->B4SOInextModel ) + { + /* loop through all the instances of the model */ + for (here = model->B4SOIinstances; here != NULL ; + here=here->B4SOInextInstance) + { + InstArray[idx] = here; idx++; - - model->B4SOIInstCount = idx; - - InstArray = TMALLOC(B4SOIinstance*, idx); - - idx = 0; - for (here = model->B4SOIinstances; here; here = here->B4SOInextInstance) - InstArray[idx++] = here; - - model->B4SOIInstanceArray = InstArray; + } + /* set the array pointer and instance count into each model */ + model->B4SOIInstCount = InstCount; + model->B4SOIInstanceArray = InstArray; } #endif diff --git a/src/spicelib/devices/hisim2/hsm2dest.c b/src/spicelib/devices/hisim2/hsm2dest.c index 6047432aa..32fbb857f 100644 --- a/src/spicelib/devices/hisim2/hsm2dest.c +++ b/src/spicelib/devices/hisim2/hsm2dest.c @@ -64,6 +64,11 @@ HSM2destroy(GENmodel **inModel) { HSM2model *mod = *(HSM2model**) inModel; +#ifdef USE_OMP + /* free just once for all models */ + FREE(mod->HSM2InstanceArray); +#endif + while (mod) { HSM2model *next_mod = mod->HSM2nextModel; HSM2instance *inst = mod->HSM2instances; @@ -72,9 +77,6 @@ HSM2destroy(GENmodel **inModel) FREE(inst); inst = next_inst; } -#ifdef USE_OMP - FREE(mod->HSM2InstanceArray); -#endif FREE(mod); mod = next_mod; } diff --git a/src/spicelib/devices/hisim2/hsm2set.c b/src/spicelib/devices/hisim2/hsm2set.c index 4d6018f71..5f5a2abbd 100644 --- a/src/spicelib/devices/hisim2/hsm2set.c +++ b/src/spicelib/devices/hisim2/hsm2set.c @@ -114,6 +114,11 @@ int HSM2setup( double Lgate =0.0, LG =0.0, Wgate =0.0, WG=0.0 ; double Lbin=0.0, Wbin=0.0, LWbin =0.0; /* binning */ +#ifdef USE_OMP + int idx, InstCount; + HSM2instance **InstArray; +#endif + /* loop through all the HSM2 device models */ for ( ;model != NULL ;model = model->HSM2nextModel ) { /* Default value Processing for HSM2 MOSFET Models */ @@ -1252,23 +1257,34 @@ do { if((here->ptr = SMPmakeElt(matrix,here->first,here->second))==(double *)NUL } /* End of model */ #ifdef USE_OMP - for (model = (HSM2model*)inModel; model; model = model->HSM2nextModel) + InstCount = 0; + model = (HSM2model*)inModel; + /* loop through all the HSM2 device models + to count the number of instances */ + + for ( ; model != NULL; model = model->HSM2nextModel ) { - HSM2instance **InstArray; - int idx; - - idx = 0; - for (here = model->HSM2instances; here; here = here->HSM2nextInstance) + /* loop through all the instances of the model */ + for (here = model->HSM2instances; here != NULL ; + here = here->HSM2nextInstance) + { + InstCount++; + } + } + InstArray = TMALLOC(HSM2instance*, InstCount); + model = (HSM2model*)inModel; + idx = 0; + for ( ; model != NULL; model = model->HSM2nextModel ) + { + /* loop through all the instances of the model */ + for (here = model->HSM2instances; here != NULL ; + here = here->HSM2nextInstance) + { + InstArray[idx] = here; idx++; - - model->HSM2InstCount = idx; - - InstArray = TMALLOC(HSM2instance*, idx); - - idx = 0; - for (here = model->HSM2instances; here; here = here->HSM2nextInstance) - InstArray[idx++] = here; - + } + /* set the array pointer and instance count into each model */ + model->HSM2InstCount = InstCount; model->HSM2InstanceArray = InstArray; } #endif