コード例 #1
0
ファイル: recordpool.cpp プロジェクト: ArildF/masters
//*****************************************************************************
// 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()
コード例 #2
0
//*****************************************************************************
// Allocate memory if we don't have any, or grow what we have.  If successful,
// then at least iRequired bytes will be allocated.
//*****************************************************************************
bool RecordPool::Grow(                 // true if successful.
    ULONG       iRequired)              // Min required bytes to allocate.
{
	// Allocate the memory.
	if (!StgPool::Grow(iRequired))
		return false;

	// Zero the new memory.
    memset(GetNextLocation(), 0, GetCbSegAvailable());

	return true;
} // bool RecordProol::Grow()
コード例 #3
0
//*****************************************************************************
// 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()