How can I free all allocated memory at once?

Posted by Tommy on Stack Overflow See other posts from Stack Overflow or by Tommy
Published on 2010-04-26T20:32:42Z Indexed on 2010/04/26 20:43 UTC
Read the original article Hit count: 289

Filed under:
|
|
|
|

Here is what I am working with:

char* qdat[][NUMTBLCOLS];
char** tdat[];
char* ptr_web_data;

    // Loop thru each table row of the query result set
    for(row_index = 0; row_index < number_rows; row_index++)
    {
        // Loop thru each column of the query result set and extract the data
        for(col_index = 0; col_index < number_cols; col_index++)
        {
            ptr_web_data = (char*) malloc((strlen(Data) + 1) * sizeof(char));
            memcpy (ptr_web_data, column_text, strlen(column_text) + 1);
            qdat[row_index][web_data_index] = ptr_web_data;
        }
     }

    tdat[row_index] = qdat[col_index];

After the data is used, the memory allocated is released one at a time using free().

for(row_index = 0; row_index < number_rows; row_index++)
{ 
  // Loop thru all columns used
  for(col_index = 0; col_index < SARWEBTBLCOLS; col_index++)
  {
    // Free memory block pointed to by results set array
    free(tdat[row_index][col_index]);
  }

}

Is there a way to release all the allocated memory at once, for this array?

Thank You.

© Stack Overflow or respective owner

Related posts about c

    Related posts about memory