Exemple #1
0
void *String::internalAlloc(uint32 nNewLength)
{
	void *pMemoryBlock;
	if (m_pString)
	{
        pMemoryBlock = ((int32 *) m_pString) - 2;
        
        if (nNewLength > getCapacity())
        {
            uint32 nCapacity = calcNewCapacity(nNewLength);
            pMemoryBlock = xRealloc(pMemoryBlock, sizeof(XCHAR)*(nCapacity + 1));
            m_pString = (XCHAR *) (((int32 *)pMemoryBlock) + 2);
            setCapacity(nCapacity);
        }
	}
	else
	{
        uint32 nCapacity = calcNewCapacity(nNewLength);
		pMemoryBlock = xAlloc(sizeof(StringData) + sizeof(XCHAR)*(nCapacity + 1));
        m_pString = (XCHAR *) (((int32 *)pMemoryBlock) + 2);
        setCapacity(nCapacity);
        *(((int32 *) m_pString) - 1) = 1;
	}

	m_pString[ nNewLength ] = 0;

	return pMemoryBlock;
}
Exemple #2
0
Btree<T>::Btree(const char* filename)
//
// Purpose: initializes the instances of a B-tree.  The
// constructor allocates dynamic memory for the array that tracks
// the deleted nodes.
//
// Parameters:
//
//     input: filename - the name of the supporting file.
//
{
    root = BTREE_NIL;
    numData = 0;
    numNodes = 0;
    numDelNodes = 0;
    // create the array that tracks the deleted nodes
    countDelNodeArray = BTREE_MIN_DEL_ARRAY;
    delNodeArray = new unsigned[countDelNodeArray];
    
    if (!delNodeArray)
      xAlloc();
    
    // assign BTREE_NIL to the elements of the array delNodeArray
    for (unsigned i = 0; i < countDelNodeArray; i++)
      *(delNodeArray + i) = BTREE_NIL;
    errMsg[0] = '\0';
    nodeSize = sizeof(Bstruct<T>);
    // open the stream for binary I/O
    f.open(filename, ios::binary | ios::in | ios::out);
    if (!f.good())
      xFileOpen();
}
Exemple #3
0
XCHAR *String::getForModify()
{
	if (!m_pString)
	{
		// In general, we optimise away small mallocs for empty strings
		// but if you ask for the non-const bytes, they must be writable
		// so we can't return "" here, like we do for the const version - jd
		void *pMemoryBlock = xAlloc(sizeof(XCHAR));
		m_pString = (XCHAR *)pMemoryBlock;
		*m_pString = 0;
	}

	return m_pString;
}