//***************************************************************************** // The Record will be added to the pool. The index of the Record in the pool // is returned in *piIndex. If the Record is already in the pool, then the // index will be to the existing copy of the Record. //***************************************************************************** void *RecordPool::AddRecord( // New record or NULL. ULONG *piIndex) // Return 1-based index of Record here. { // Space on heap for new Record? if (m_cbRec > GetCbSegAvailable()) { if (!Grow(m_cbRec)) return 0; } // Records should be aligned on record boundaries. _ASSERTE((GetNextOffset() % m_cbRec) == 0); // Copy the Record to the heap. void *pNewRecord = GetNextLocation(); // Give the 1-based index back to caller. if (piIndex) *piIndex = (GetNextOffset() / m_cbRec) + 1; // Update heap counters. SegAllocate(m_cbRec); SetDirty(); return pNewRecord; } // void *RecordPool::AddRecord()
//***************************************************************************** // The Record will be added to the pool. The index of the Record in the pool // is returned in *piIndex. If the Record is already in the pool, then the // index will be to the existing copy of the Record. //***************************************************************************** void *RecordPool::AddRecord( // New record or NULL. ULONG *piIndex) // Return 1-based index of Record here. { #ifdef _DEBUG { // Instrumentation for OOM fault injection testing: make sure we can OOM every call to AddRecord. char *p = new (nothrow) char; if (!p) { return 0; } delete p; } #endif // Space on heap for new Record? if (m_cbRec > GetCbSegAvailable()) { if (!Grow(m_cbRec)) return 0; } // Records should be aligned on record boundaries. _ASSERTE((GetNextOffset() % m_cbRec) == 0); // Copy the Record to the heap. void *pNewRecord = GetNextLocation(); // Give the 1-based index back to caller. if (piIndex) *piIndex = (GetNextOffset() / m_cbRec) + 1; // Update heap counters. SegAllocate(m_cbRec); SetDirty(); return pNewRecord; } // void *RecordPool::AddRecord()