Esempio n. 1
0
void CDataBuffer::Add(char c)
{
	if (_allocated == _length){
		ReAllocate();
	}
	GetBuffer()[_length++] = (unsigned char)c;
}
Esempio n. 2
0
void CImage::ReAllocate(CShape s, const type_info& ti, int bandSize,
                        bool evenIfShapeDiffers)
{
    if (! evenIfShapeDiffers && s == m_shape && ti == *m_pTI && bandSize == m_bandSize)
        return;
    ReAllocate(s, ti, bandSize, 0, true, 0);
}
Esempio n. 3
0
static gen GenNumber(char *gname, int status) {
	unsigned        i;

	if (status == CREATE && NrGens == 0)  /* Initialize GenNames[]. */
		GenNames = (char **)Allocate(128 * sizeof(char*));

	for (i = 1; i <= NrGens; i++)  /* Find the generator name. */
		if (strcmp(gname, GenNames[i]) == 0) {
			if (status == CREATE) return (gen)0;
			return (gen)i;
		}

	/* It's a new generator. */
	if (status == NOCREATE) return (gen)0;
	NrGens++;
	if (NrGens % 128 == 0)
		GenNames = (char **)ReAllocate((void *)GenNames,
		                               (NrGens + 128) * sizeof(char *));

	i = strlen(gname);
	GenNames[ NrGens ] = (char *)Allocate((i + 1) * sizeof(char));
	strcpy(GenNames[NrGens], gname);

	return NrGens;
}
Esempio n. 4
0
String& String::operator+=(const String &str)
{
    if(!str.curLength)
        return *this;

    curLength += str.curLength;

    if(curLength)
    {
        if(lpString)
        {
            lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
            scat(lpString, str.lpString);
        }
        else
        {
            lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR));
            scpy(lpString, str.lpString);
        }
    }
    else
    {
        if(lpString)
            Free(lpString);
        lpString = NULL;
    }

    return *this;
}
		void * ReAllocate(void * Pointer, size_t Size, const c8 * FileName, u32 LineNum)
		{
			RemovePointer(Pointer, FileName, LineNum, 0);
			void * NewPointer = ReAllocate(Pointer, Size);
			AddPointer(NewPointer, FileName, LineNum, 0, Size);
			return NewPointer;
		}
Esempio n. 6
0
void String::InsertString(UINT dwPos, CTSTR str)
{
    assert(str);
    if(!str) return;

    assert(dwPos <= curLength);

    if(dwPos == curLength)
    {
        AppendString(str);
        return;
    }

    UINT strLength = slen(str);

    if(strLength)
    {
        lpString = (TSTR)ReAllocate(lpString, (curLength+strLength+1)*sizeof(TCHAR));

        TSTR lpPos = lpString+dwPos;
        mcpyrev(lpPos+strLength, lpPos, ((curLength+1)-dwPos)*sizeof(TCHAR));
        mcpy(lpPos, str, strLength*sizeof(TCHAR));

        curLength += strLength;
    }
}
Esempio n. 7
0
BitKey & BitKey::operator=(const BitKey & bit_list)
{
  if(iv_Capacity)
  {
    BitString bs(iv_Capacity,DataPtr());
    bs.Pattern(0x00000000);
  }
  ReAllocate(bit_list.iv_Capacity);
  if(IsDirect()) // implies bit_list is also direct
  {
    iv_storage1 = bit_list.iv_storage1;
    iv_rep.storage2 = bit_list.iv_rep.storage2;
  }
  else
  {
    const uint32_t * dataPtr = NULL;
    if(bit_list.IsDirect())
    {
      dataPtr = &bit_list.iv_storage1;
    } else
    {
      dataPtr = bit_list.iv_rep.buffer;
    }
    memcpy(iv_rep.buffer,dataPtr,4*getWordSize(bit_list.iv_Capacity));
  }
  return(*this);
}
Esempio n. 8
0
String& String::AppendString(CTSTR str, UINT count)
{
    UINT strLength;
    
    if(!str)
        strLength = 0;
    else if(count)
        strLength = MIN(slen(str), count);
    else
        strLength = slen(str);

    if(!strLength)
        return *this;

    UINT oldLen = curLength;

    curLength += strLength;

    if(curLength)
    {
        lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
        scpy_n(lpString+oldLen, str, strLength);
    }
    else
    {
        if(lpString)
            Free(lpString);
        lpString = NULL;
    }

    return *this;
}
Esempio n. 9
0
void CDataBuffer::Add(const char* data, int length)
{
	if (length + _length > _allocated){
		int factor = ((length + _length) / (_allocated)) + 1;
		ReAllocate(factor);
	}
	memcpy(&GetBuffer()[_length],data,length);
	_length += length;
}
Esempio n. 10
0
CDataBuffer::CDataBuffer(const char* data,int length) : _length(0),_allocated(DATA_BUFFER_DEFAULT_SIZE),
_destroy(false),_data_ptr(NULL)
{
	if (length > _allocated){
		ReAllocate((length / _allocated) + 1);
	}
	memcpy(&GetBuffer()[0],data,length);
	_length = length;
}
Esempio n. 11
0
void BitKey::setBit(uint32_t i_bitValue)
{
  if(i_bitValue >= iv_Capacity)
  {
    ReAllocate(i_bitValue+1);
  }
  BitString bs(iv_Capacity,DataPtr());
  bs.Set(i_bitValue);
}
Esempio n. 12
0
String& String::operator+=(TCHAR ch)
{
    ++curLength;
    lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
    lpString[curLength-1] = ch;
    lpString[curLength]   = 0;

    return *this;
}
Esempio n. 13
0
String& String::operator=(TCHAR ch)
{
    curLength = 1;
    lpString = (TSTR)ReAllocate(lpString, 2);
    *lpString = ch;
    lpString[1] = 0;

    return *this;
}
Esempio n. 14
0
BOOL AllocateTimerArray(VOID)
{
    LPVOID	lpMemory;
    //	Allocate more memory for next timer
    //z 初始的时候 dwTimerListItems 为0。每次增加1000,为啥不用 1024 了。
    if (! (lpMemory = ReAllocate(lpTimerList, "Timer:Array", (dwTimerListItems + 1000) * sizeof(LPTIMER)))) return TRUE;
    dwTimerListSize	+= 1000;
    lpTimerList	= (LPTIMER *)lpMemory;
    return FALSE;
}
Esempio n. 15
0
BOOL DynamicBuffer::InsertDataIntoTail(CPCVOID cpcData, CONST size_t nDataBytes)
{
	CHECK_RETURN_BOOL_QUIET(NULL != cpcData && m_nTotalSize > 0 && m_nUsedSize <= m_nTotalSize);
	while (m_nTotalSize - m_nUsedSize < nDataBytes)
	{
		ReAllocate();
	}

	size_t nUsedSize = m_nUsedSize + nDataBytes;
	while (m_nTotalSize - nUsedSize < DEFAULT_MAX_BUFFER_LEN)
	{
		ReAllocate();
	}

	PCHAR pLeft = static_cast<PCHAR>(m_pvData) + m_nUsedSize;
	::memcpy(pLeft, cpcData, nDataBytes);
	m_nUsedSize = nUsedSize;

	return TRUE;
}
Esempio n. 16
0
BitKey & BitKey::operator=(const BitString & bit_string)
{
  if(iv_Capacity)
  {
    BitString bs(iv_Capacity,DataPtr());
    bs.Pattern(0x00000000);
  }
  ReAllocate(bit_string.GetLength());
  BitString dbs(iv_Capacity,DataPtr());
  dbs.SetBits(bit_string);
  return(*this);
}
Esempio n. 17
0
BOOL DynamicBuffer::InsertDataIntoHead(CPCVOID cpcData, CONST size_t nDataBytes)
{
	CHECK_RETURN_BOOL_QUIET(NULL != cpcData && m_nTotalSize > 0 && m_nUsedSize <= m_nTotalSize);
	while (m_nTotalSize - m_nUsedSize < nDataBytes)
	{
		ReAllocate();
	}

	CONST PCHAR pData = static_cast<CONST PCHAR>(m_pvData);
	::memmove(pData + nDataBytes, pData, m_nUsedSize);
	::memcpy(pData, cpcData, nDataBytes);

	m_nUsedSize += nDataBytes;
	return TRUE;
}
Esempio n. 18
0
String& String::InsertChar(UINT pos, TCHAR chr)
{
    if(pos > curLength)
    {
        AppWarning(TEXT("String::InsertChar - bad index specified"));
        return *this;
    }
    
    ++curLength;
    lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
    if(curLength > 1)
        mcpyrev(lpString+pos+1, lpString+pos, (curLength-pos)*sizeof(TCHAR));

    lpString[pos] = chr;

    return *this;
}
Esempio n. 19
0
void String::RemoveRange(unsigned int from, unsigned int to)
{
    assert(from < to);
    assert(to <= curLength);
    if(from >= to || to > curLength) return;

    unsigned int delLength = to-from;
    if(delLength == curLength)
    {
        Clear();
        return;
    }

    unsigned int remainderLength = (curLength+1)-to;
    curLength -= delLength;
    mcpy(lpString+from, lpString+to, remainderLength*sizeof(TCHAR));
    lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
}
Esempio n. 20
0
BOOL DynamicBuffer::InsertDataIntoPos (CONST size_t nPos, CPCVOID cpcData, CONST size_t nDataBytes)
{
	CHECK_RETURN_BOOL_QUIET(nPos >= 0 && nPos < m_nUsedSize);
	CHECK_RETURN_BOOL_QUIET(NULL != cpcData && m_nTotalSize > 0);
	CHECK_RETURN_BOOL_QUIET(m_nUsedSize <= m_nTotalSize);

	while (m_nTotalSize - m_nUsedSize < nDataBytes)
	{
		ReAllocate();
	}

	PCHAR pPos = static_cast<PCHAR>(m_pvData) + nPos;

	::memmove(pPos + nDataBytes, pPos, m_nUsedSize);
	::memcpy(pPos, cpcData, nDataBytes);

	m_nUsedSize += nDataBytes;
	return TRUE;
}
/**
 * get a slot for a knob
 */
int MutexKnobData::GetMutexKnobDataIndex()
{
    int oldsize, newsize;
    QMutexLocker locker(&mutex);
    for(int i=0; i < KnobDataArraySize; i++) {
        if(KnobData[i].index == -1) {
            return i;
        }
    }
    oldsize=KnobDataArraySize;
    newsize = KnobDataArraySize+200;
    void *p = &KnobData;
    ReAllocate(oldsize * sizeof(knobData), newsize * sizeof(knobData), (void**) p);
    for(int i=oldsize; i < newsize; i++){
        KnobData[i].index  = -1;
    }
    KnobDataArraySize=newsize;
    return oldsize;
}
Esempio n. 22
0
void DynamicQueue<TX>::Put(const TX & obj) {
   // Add object to buffer, return index

   if (NumEntries >= MaxNum) {
      // buffer too small or no buffer. Allocate more memory
      // Determine new size = 2 * current size + the number of objects that correspond to AllocateSpace
      int NewSize = MaxNum * 2 + (AllocateSpace+sizeof(TX)-1)/sizeof(TX);

      ReAllocate(NewSize);
   }
   // Insert new object at head
   Buffer[head] = obj;
   // Delete old buffer after copying object, in case obj was in old buffer
   if (OldBuffer) {nb_free(OldBuffer);  OldBuffer = 0;}
   // Make head point to next vacant slot
   if (++head >= MaxNum) head = 0;
   // Count entries
   NumEntries++;
}
Esempio n. 23
0
String& String::operator=(CTSTR str)
{
    if(!str)
        curLength = 0;
    else
        curLength = slen(str);

    if(curLength)
    {
        lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
        scpy(lpString, str);
    }
    else
    {
        if(lpString)
            Free(lpString);
        lpString = NULL;
    }

    return *this;
}
Esempio n. 24
0
String& String::RemoveChar(UINT pos)
{
    if(pos >= curLength)
    {
        AppWarning(TEXT("String::RemoveChar - bad index specified"));
        return *this;
    }
    
    
    if(curLength == 1)
        Clear();
    else
    {
        if(pos < curLength)
            mcpy(lpString+pos, lpString+pos+1, (curLength-pos)*sizeof(TCHAR));
        lpString = (TSTR)ReAllocate(lpString, (curLength)*sizeof(TCHAR));
        --curLength;
    }

    return *this;
}
Esempio n. 25
0
String& String::SetLength(UINT length)
{
    UINT oldLength = curLength;

    curLength = length;
    if(curLength)
    {
        lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));

        if(oldLength < curLength)
            zero(&lpString[oldLength], ((curLength+1)-oldLength)*sizeof(TCHAR));
        else
            lpString[length] = 0;
    }
    else
    {
        if(lpString)
            Free(lpString);
        lpString = NULL;
    }

    return *this;
}
Esempio n. 26
0
void DynamicQueue<TX>::Reserve(int num) {
   // Allocate buffer of the specified size
   // Setting num > current MaxNum will allocate a larger buffer and 
   // move all data to the new buffer.
   // Setting num <= current MaxNum will do nothing. The buffer will 
   // only grow, not shrink.
   // Setting num = 0 will discard all data and de-allocate the buffer.
   if (num <= MaxNum) {
      if (num <= 0) {
         if (num < 0) Error(1, num);
         // num = 0. Discard data and de-allocate buffer
         if (Buffer) nb_free(Buffer);            // De-allocate buffer
         Buffer = 0;                             // Reset everything
         MaxNum = NumEntries = head = tail = 0;
         return;
      }
      // Request to reduce size. Ignore
      return;
   }
   // num > MaxNum. Increase Buffer
   ReAllocate(num);
   // OldBuffer must be deleted after calling ReAllocate
   if (OldBuffer) {nb_free(OldBuffer);  OldBuffer = 0;}
}
Esempio n. 27
0
String& String::operator+=(CTSTR str)
{
    UINT strLength;
    
    if(!str)
        strLength = 0;
    else
        strLength = slen(str);

    if(!strLength)
        return *this;

    curLength += strLength;

    if(curLength)
    {
        if(lpString)
        {
            lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));
            scat(lpString, str);
        }
        else
        {
            lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR));
            scpy(lpString, str);
        }
    }
    else
    {
        if(lpString)
            Free(lpString);
        lpString = NULL;
    }

    return *this;
}
Esempio n. 28
0
String& String::FindReplace(CTSTR strFind, CTSTR strReplace)
{
    if(!lpString)
        return *this;

    if(!strReplace) strReplace = TEXT("");

    int findLen = slen(strFind), replaceLen = slen(strReplace);
    TSTR lpTemp = lpString;

    if(replaceLen < findLen)
    {
        int nOccurences = 0;

        while(lpTemp = sstr(lpTemp, strFind))
        {
            TSTR lpEndSegment = lpTemp+findLen;
            UINT endLen = slen(lpEndSegment);

            if(endLen)
            {
                mcpy(lpTemp+replaceLen, lpEndSegment, (endLen+1)*sizeof(TCHAR));
                mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR));
            }
            else
                scpy(lpTemp, strReplace);

            lpTemp += replaceLen;
            ++nOccurences;
        }

        if(nOccurences)
            curLength += (replaceLen-findLen)*nOccurences;
    }
    else if(replaceLen == findLen)
    {
        while(lpTemp = sstr(lpTemp, strFind))
        {
            mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR));
            lpTemp += replaceLen;
        }
    }
    else
    {
        int nOccurences = 0;

        while(lpTemp = sstr(lpTemp, strFind))
        {
            lpTemp += findLen;
            ++nOccurences;
        }

        if(nOccurences)
        {
            curLength += (replaceLen-findLen)*nOccurences;

            lpTemp = lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR));

            while(lpTemp = sstr(lpTemp, strFind))
            {
                TSTR lpEndSegment = lpTemp+findLen;
                UINT endLen = slen(lpEndSegment);

                if(endLen)
                {
                    mcpyrev(lpTemp+replaceLen, lpEndSegment, (endLen+1)*sizeof(TCHAR));
                    mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR));
                }
                else
                    scpy(lpTemp, strReplace);

                lpTemp += replaceLen;
            }
        }
    }

    return *this;
}
Esempio n. 29
0
void CImage::DeAllocate()
{
    // Release the memory & set to default values
    ReAllocate(CShape(), *(const type_info *) 0, 0, 0, false, 0);
    SetDefaults();
}
Esempio n. 30
0
CImage::CImage(CShape s, const type_info& ti, int cS)
{
    SetDefaults();
    ReAllocate(s, ti, cS, 0, true, 0);
}