CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

delete[]



Can any one help?


int IS34Table::AddRecord(const IS34DATAREC &_Data)
{
    IS34Record	**pTempArray;

    if((iRecords % iDelta) == 0){		// Record table array re-allocation required?
	// YES: Re-allocate record array space and copy existing table
	pTempArray = pRecArray;
	pRecArray  = new IS34Record *[iRecords + iDelta];
	memcpy(pRecArray, pTempArray, iRecords * sizeof(IS34Record*)); // Copy existing record table array
	OutputDebugString("START: delete" );
	delete[] pTempArray;		// EXCEPTION GENERATED HERE
	OutputDebugString("END:   delete" );
    }
    iCurrent = iRecords;
// New current record
    pRecArray[iRecords++] = new IS34Record(_Data);	// Add record to record table array
    return(iCurrent + 1);
}

The code above generates an access violation on the delete statement
surrounded by OutputDebugString statements after approximately 200 calls
to the function. The record data size is small and no meory allocation
errors occur. The block of code simply adds pointers to new records as
they are added. when the record pointer array is full a new array of
size current+delta is generated and the existing pointers copied. Why it
creates an exception is baffling me and any help would be appreciated.
Another factor is that when runnin gin debug mode the debug doesn't
apprear when the exception is generated.
 
Note iRecords holds the number of records.

Ashley Sutton



W Komornicki's Home Page | Main Index | Thread Index