void CPtrArray::InsertAt(int nIndex, void* newElement, int nCount) { // ASSERT_VALID(this); // ASSERT(nIndex >= 0); // will expand to meet need // ASSERT(nCount > 0); // zero or negative size not allowed if (nIndex >= m_nSize) { // adding after the end of the array SetSize(nIndex + nCount); // grow so nIndex is valid } else { // inserting in the middle of the array int nOldSize = m_nSize; SetSize(m_nSize + nCount); // grow it to new size // shift old data up to fill gap _memmove(&m_pData[nIndex+nCount], &m_pData[nIndex], (nOldSize-nIndex) * sizeof(void*)); // re-init slots we copied from memset(&m_pData[nIndex], 0, nCount * sizeof(void*)); } // insert new value in the gap // ASSERT(nIndex + nCount <= m_nSize); while (nCount--) m_pData[nIndex++] = newElement; }
/* * Copy s1 to s2, always copy n bytes. * For overlapped copies it does the right thing. */ void bcopy(char *s1, char *s2, int len) { if (len > 0) (void) _memmove(s2, s1, (size_t)len); }