 |
A QSprob data structure always contains names for each row of the LP problem; if the application does not give explicit row names, then the QSopt library will generate them when the problem is loaded and as new rows are added. The QSget_rownames function will allocate memory for each of the strings that are returned via the array of pointers in rownames ; when the application no longer needs the names, the memory associated with each of the strings should be freed; since the memory for the strings was allocated by the QSopt library, the memory must be freed with calls to QSfree rather than by the system free() function.
|
 |
/* p is an initialized QSprob, a handle to an existing LP problem */
int rval, nrows, i;
char **rownames;
nrows = QSget_rowcount (p);
rownames = (char **) malloc (nrows * sizeof (char *));
rval = QSget_rownames (p, rownames);
if (rval) {
fprintf (stderr,
"Could not get row names, error code %d\n", rval);
} else {
printf ("Constraint Names\n");
for (i = 0; i < nrows; i++) {
printf ("%s\n", rownames[i]);
}
/* Need to free the individual names */
for (i = 0; i < nrows; i++) {
/* Use QSfree for mem allocated by QSopt */
QSfree (rownames[i]);
}
}
/* Use free for mem allocated by system malloc */
free (rownames);
|