コード例 #1
0
void VDChunkedBuffer::Write(const void *data, uint32 size) {
	if (!size)
		return;

	while(size) {
		if (mActiveChunks.empty())
			AllocChunk();

		ChunkInfo& ci = mActiveChunks.back();
		uint32 tc = ci.mChunkSize - mChunkHead;
		if (tc > size)
			tc = size;

		if (!tc) {
			AllocChunk();
			mChunkHead = 0;
			continue;
		}

		memcpy((char *)ci.mpChunk + mChunkHead, data, tc);
		data = (const char *)data + tc;
		size -= tc;
		mChunkHead += tc;
	}
}
コード例 #2
0
ファイル: XtObjPool_2.cpp プロジェクト: tempbottle/xtrovert
xt_size_t CXtObjPool::InflateRealCapacity(void)
{
	xt_size_t nRet = 0;
	xt_poolchk_node_t *pChunk = NULL;

	/*
		Return : 0  for error.
				inflated capacity.
	*/

	nRet = GetGrowRealCapacity();
	if ( nRet == 0 )
	{
		return 0;
	}

	pChunk = AllocChunk( nRet );
	if ( pChunk == NULL )
	{
		return 0;
	}

	EmployChunk( pChunk );

	OnInflateRealCapacity( pChunk );

	return nRet;
}
コード例 #3
0
ファイル: fgas_memory.cpp プロジェクト: hfiguiere/pdfium
void* CFX_FixedStore::Alloc(size_t size) {
  if (size > m_iBlockSize) {
    return nullptr;
  }
  FX_FIXEDSTORECHUNK* pChunk = m_pChunk;
  while (pChunk) {
    if (pChunk->iFreeNum > 0) {
      break;
    }
    pChunk = pChunk->pNextChunk;
  }
  if (!pChunk) {
    pChunk = AllocChunk();
  }
  uint8_t* pFlags = pChunk->FirstFlag();
  size_t i = 0;
  for (; i < pChunk->iChunkSize; i++)
    if (pFlags[i] == 0) {
      break;
    }
  ASSERT(i < pChunk->iChunkSize);
  pFlags[i] = 1;
  pChunk->iFreeNum--;
  return pChunk->FirstBlock() + i * m_iBlockSize;
}
コード例 #4
0
ファイル: fgas_memory.cpp プロジェクト: hfiguiere/pdfium
FX_STATICSTORECHUNK* CFX_StaticStore::FindChunk(size_t size) {
  ASSERT(size != 0);
  if (!m_pLastChunk || m_pLastChunk->iFreeSize < size) {
    return AllocChunk(std::max(m_iDefChunkSize, size));
  }
  return m_pLastChunk;
}
コード例 #5
0
ファイル: DzCot.c プロジェクト: Foreverflying/DzCot
void* DzAllocPermanentChunk( size_t size )
{
    DzHost* host = GetHost();
    assert( host );
    assert( size % MIN_PERMANENT_CHUNK_SIZE == 0 );

    return AllocChunk( host, size );
}
コード例 #6
0
ファイル: cmssheet.cpp プロジェクト: UIKit0/digikam
/* Allocates a string */
static
char *AllocString(LPIT8 it8, const char* str)
{
    int Size = strlen(str)+1;
    char *ptr;
    ptr = (char *) AllocChunk(it8, Size);
    if (ptr) strncpy (ptr, str, Size);
    return ptr;
}
コード例 #7
0
ファイル: cmssheet.cpp プロジェクト: UIKit0/digikam
static
void AllocateDataSet(LPIT8 it8)
{
    if (it8 -> Data) return;    /* Already allocated */

    it8-> nSamples   = atoi(cmsxIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
    it8-> nPatches   = atoi(cmsxIT8GetProperty(it8, "NUMBER_OF_SETS"));
    it8-> Data = (char**)AllocChunk (it8, (it8->nSamples + 1) * (it8->nPatches + 1) *sizeof (char*));
    if (it8->Data == NULL)
    {
        cmsSignalError(-1, "AllocateDataSet: Unable to allocate data array");
    }

}
コード例 #8
0
ファイル: cmssheet.cpp プロジェクト: UIKit0/digikam
/* Add a property into a linked list */
static
BOOL AddToList(LPIT8 it8, LPKEYVALUE* Head, const char *Key, const char* Value)
{
    LPKEYVALUE p;
    LPKEYVALUE last;


    /* Check if property is already in list (this is an error) */

    if (IsAvailableOnList(*Head, Key, &last)) {
                    cmsSignalError(LCMS_ERRC_ABORTED, "duplicate key <%s>", Key);
        return false;
    }

        /* Allocate the container */
    p = (LPKEYVALUE) AllocChunk(it8, sizeof(KEYVALUE));
    if (p == NULL)
    {
        cmsSignalError(LCMS_ERRC_ABORTED, "AddToList: out of memory");
        return false;
    }

    /* Store name and value */
    p->Keyword = AllocString(it8, Key);

    if (Value)
        p->Value   = AllocString(it8, Value);
    else
        p->Value   = NULL;

    p->Next    = NULL;

    /* Keep the container in our list */
    if (*Head == NULL)
        *Head = p;
    else
        last->Next = p;

    return true;
}
コード例 #9
0
ファイル: ac_memory.cpp プロジェクト: gaopan461/acoral
	void* SmallMemoryAlloc::allocate(size_t size)
	{
		size_t idx = ChunkIndex(size);
		ACCHECK(idx < CST_CHUNK_NUMBER);

		//锁指定大小的内存池
		ThreadGuard guard(&m_vtGuard[idx]);

		SMemoryList* &temp = m_vtFreeList[idx];
		if (!temp)
		{
			//内存池空,分配一个新的chunk做内存池
			SMemoryList* newChunk=AllocChunk(idx);
			SChunkList* chunkNode;

			//此处chunkNode也通过Memory分配器分配内存
			if(ChunkIndex(sizeof(SChunkList)) == idx)
			{
				chunkNode = reinterpret_cast<SChunkList *>(temp);
				temp = temp->m_pNext;
			}
			else
			{
				chunkNode = reinterpret_cast<SChunkList *>(allocate(sizeof(SChunkList)));
			}

			ThreadGuard guard(&m_nChunkGuard);

			//将新分配出来的chunk链接到chunk链表表头
			chunkNode->m_pNext = m_pChunkList;
			chunkNode->m_pData = newChunk;
			m_pChunkList = chunkNode;
		}

		//从内存池中取出一个内存
		void* ret = temp;
		temp = temp->m_pNext;
		return ret;
	}
コード例 #10
0
ファイル: cmssheet.cpp プロジェクト: UIKit0/digikam
static
void AllocateDataFormat(LPIT8 it8)
{
    if (it8 -> DataFormat) return;    /* Already allocated */

    // work around a crash on invalid profile, see bug #229370
    const char *numberOfFields = cmsxIT8GetProperty(it8, "NUMBER_OF_FIELDS");
    if (numberOfFields)
        it8 -> nSamples  = atoi(numberOfFields);
    else it8 -> nSamples = 0;

    if (it8 -> nSamples <= 0) {

        cmsSignalError(LCMS_ERRC_WARNING, "AllocateDataFormat: Unknown NUMBER_OF_FIELDS, assuming 10");
        it8 -> nSamples = 10;
        }

    it8 -> DataFormat = (char**) AllocChunk (it8, (it8->nSamples + 1) * sizeof(char *));
    if (it8->DataFormat == NULL)
    {
        cmsSignalError(LCMS_ERRC_ABORTED, "AllocateDataFormat: Unable to allocate dataFormat array");
    }

}