void array_remove(struct array *a, unsigned index) { unsigned num_to_move; ARRAYASSERT(a->num <= a->max); ARRAYASSERT(index < a->num); num_to_move = a->num - (index + 1); memmove(a->v + index, a->v + index+1, num_to_move*sizeof(void *)); a->num--; }
//=============================================================================================== // PROCEDURE: _GetReadMode // PURPOSE: Retrieves synch entries from the virtualized array. // BOOL CSynch::_GetReadMode( UINT uFirstEntry, Synch *pSynch, UINT uEntries ) { MEMBERASSERT(); ASSERT(m_hfSynchFile != INVALID_HANDLE_VALUE); ASSERT(uEntries > 0); ARRAYASSERT(pSynch, uEntries); ASSERT(uFirstEntry+uEntries <= m_uSynchCount); ASSERT(m_eMode == eREADMODE); // Loop until the get() has been satisfied. while (uEntries) { // If the first entry is not in the cache, reload the cache. if ((uFirstEntry < m_uCacheStart) || (uFirstEntry >= m_uCacheStart + m_uCacheCount)) { m_uCacheStart = uFirstEntry - (uFirstEntry % SYNCH_BUFFER_SIZE); m_uCacheCount = m_uSynchCount - m_uCacheStart; if (m_uCacheCount > SYNCH_BUFFER_SIZE) m_uCacheCount = SYNCH_BUFFER_SIZE; Read( m_SynchBuffer, m_uCacheStart, m_uCacheCount ); } // Calculate how many entries intersect the cache. UINT uCount = min(uEntries, m_uCacheCount); // Copy the entries out of the cache. memcpy(pSynch, m_SynchBuffer+uFirstEntry-m_uCacheStart, uCount*sizeof(Synch)); uFirstEntry += uCount; pSynch += uCount; uEntries -= uCount; } return TRUE; }
//=============================================================================================== // FUNCTION: GetDACFileSweep // PURPOSE: Reads a sweep from the DAC file array. // BOOL CFileDescriptor::GetDACFileSweep(UINT uDACChannel, UINT uSweep, DAC_VALUE *pnData, UINT uMaxLength) { MEMBERASSERT(); ASSERT( uDACChannel < ABF_WAVEFORMCOUNT ); ARRAYASSERT( pnData, uMaxLength ); return m_DACFile[uDACChannel].GetSweep( uSweep, pnData, uMaxLength ); }
void array_cleanup(struct array *a) { /* * Require array to be empty - helps avoid memory leaks since * we don't/can't free anything any contents may be pointing * to. */ ARRAYASSERT(a->num == 0); kfree(a->v); #ifdef ARRAYS_CHECKED a->v = NULL; #endif }
//=============================================================================================== // PROCEDURE: _GetWriteMode // PURPOSE: Retrieves synch entries from the virtualized array. // BOOL CSynch::_GetWriteMode( UINT uFirstEntry, Synch *pSynch, UINT uEntries ) { MEMBERASSERT(); ASSERT(uFirstEntry+uEntries <= m_uSynchCount); ASSERT(uEntries > 0); ARRAYASSERT(pSynch, uEntries); ASSERT(m_eMode == eWRITEMODE); // If just the last entry is required, return it and get out. if (uFirstEntry == m_uSynchCount-1) { *pSynch = m_LastEntry; return TRUE; } // If the block requested is not contained completely in the cache, // read the file for it, reading straight into the passed buffer. if (m_uSynchCount - uFirstEntry > SYNCH_BUFFER_SIZE) { // Rather than checking whether the file has been opened in this case // we will just assert that this is so here. This means that it is the // responsibility of the caller to ensure that synch entries are not // requested outside the synch buffer if the cache is not backed by a file. ASSERT(m_hfSynchFile != INVALID_HANDLE_VALUE); // Calculate how many entries there are from the requested first entry until // we hit the ones currently in the cache. UINT uCount = m_uSynchCount - uFirstEntry - SYNCH_BUFFER_SIZE; // Limit the count to no greater than the requested amount. if (uCount > uEntries) uCount = uEntries; // Read the data out of the file. if( !Read( pSynch, uFirstEntry, uCount) ) return FALSE; // Update pointers and counters. pSynch += uCount; uFirstEntry += uCount; uEntries -= uCount; if (uEntries == 0) return TRUE; } // Transfer the part of the buffer that is "invalidated", i.e. about to be overwritten. if (uFirstEntry < m_uCacheStart) { UINT uCount = m_uCacheStart - uFirstEntry; ASSERT(uCount <= SYNCH_BUFFER_SIZE - m_uCacheCount); Synch *pS = m_SynchBuffer + SYNCH_BUFFER_SIZE - uCount; if (uCount > uEntries) uCount = uEntries; memcpy(pSynch, pS, uCount*sizeof(Synch)); pSynch += uCount; uFirstEntry += uCount; uEntries -= uCount; if (uEntries == 0) return TRUE; } // Transfer the more recently written part of the cache. ASSERT(uFirstEntry >= m_uCacheStart); ASSERT(uFirstEntry - m_uCacheStart + uEntries <= m_uCacheCount); memcpy(pSynch, m_SynchBuffer + uFirstEntry - m_uCacheStart, uEntries*sizeof(Synch)); return TRUE; }
//=============================================================================================== // FUNCTION: ReadDeltas // PURPOSE: Reads a sub section of the Delta array. // BOOL CFileDescriptor::ReadDeltas( UINT uFirstDelta, ABFDelta *pDeltaArray, UINT uNumDeltas) { MEMBERASSERT(); ARRAYASSERT( pDeltaArray, uNumDeltas ); return m_Deltas.Get( uFirstDelta, pDeltaArray, uNumDeltas ); }
//=============================================================================================== // FUNCTION: ReadTags // PURPOSE: Reads a sub section of the tag array. // BOOL CFileDescriptor::ReadTags( UINT uFirstTag, ABFTag *pTagArray, UINT uNumTags) { MEMBERASSERT(); ARRAYASSERT( pTagArray, uNumTags ); return m_Tags.Get( uFirstTag, pTagArray, uNumTags ); }