本文整理汇总了C++中RTMemRealloc函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemRealloc函数的具体用法?C++ RTMemRealloc怎么用?C++ RTMemRealloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemRealloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: png_write_data_fn
static void PNGAPI png_write_data_fn(png_structp png_ptr, png_bytep p, png_size_t cb)
{
PNGWriteCtx *pCtx = (PNGWriteCtx *)png_get_io_ptr(png_ptr);
LogFlowFunc(("png_ptr %p, p %p, cb %d, pCtx %p\n", png_ptr, p, cb, pCtx));
if (pCtx && RT_SUCCESS(pCtx->rc))
{
if (pCtx->cbAllocated - pCtx->cbPNG < cb)
{
uint32_t cbNew = pCtx->cbPNG + (uint32_t)cb;
AssertReturnVoidStmt(cbNew > pCtx->cbPNG && cbNew <= _1G, pCtx->rc = VERR_TOO_MUCH_DATA);
cbNew = RT_ALIGN_32(cbNew, 4096) + 4096;
void *pNew = RTMemRealloc(pCtx->pu8PNG, cbNew);
if (!pNew)
{
pCtx->rc = VERR_NO_MEMORY;
return;
}
pCtx->pu8PNG = (uint8_t *)pNew;
pCtx->cbAllocated = cbNew;
}
memcpy(pCtx->pu8PNG + pCtx->cbPNG, p, cb);
pCtx->cbPNG += (uint32_t)cb;
}
}
示例2:
/**
* Allocates additional space for the block.
*
* @returns Pointer to the new unused space or NULL if out of memory.
* @param pThis The VUSB sniffer instance.
* @param cbAdditional The additional memory requested.
*/
static void *vusbSnifferBlockAllocSpace(PVUSBSNIFFERINT pThis, uint32_t cbAdditional)
{
/* Fast path where we have enough memory allocated. */
if (pThis->cbBlockCur + cbAdditional <= pThis->cbBlockMax)
{
void *pv = pThis->pbBlockData + pThis->cbBlockCur;
pThis->cbBlockCur += cbAdditional;
return pv;
}
/* Allocate additional memory. */
uint32_t cbNew = pThis->cbBlockCur + cbAdditional;
uint8_t *pbDataNew = (uint8_t *)RTMemRealloc(pThis->pbBlockData, cbNew);
if (pbDataNew)
{
pThis->pbBlockData = pbDataNew;
pThis->pBlockHdr = (PDumpFileBlockHdr)pbDataNew;
void *pv = pThis->pbBlockData + pThis->cbBlockCur;
pThis->cbBlockCur = cbNew;
pThis->cbBlockMax = cbNew;
return pv;
}
return NULL;
}
示例3: rtEnvIntAppend
/**
* Appends an already allocated string to papszEnv.
*
* @returns IPRT status code
* @param pIntEnv The environment block to append it to.
* @param pszEntry The string to add. Already duplicated, caller
* does error cleanup.
*/
static int rtEnvIntAppend(PRTENVINTERNAL pIntEnv, char *pszEntry)
{
/*
* Do we need to resize the array?
*/
int rc = VINF_SUCCESS;
size_t iVar = pIntEnv->cVars;
if (iVar + 2 > pIntEnv->cAllocated)
{
void *pvNew = RTMemRealloc(pIntEnv->papszEnv, sizeof(char *) * (pIntEnv->cAllocated + RTENV_GROW_SIZE));
if (!pvNew)
rc = VERR_NO_MEMORY;
else
{
pIntEnv->papszEnv = (char **)pvNew;
pIntEnv->cAllocated += RTENV_GROW_SIZE;
for (size_t iNewVar = pIntEnv->cVars; iNewVar < pIntEnv->cAllocated; iNewVar++)
pIntEnv->papszEnv[iNewVar] = NULL;
}
}
if (RT_SUCCESS(rc))
{
/*
* Append it.
*/
pIntEnv->papszEnv[iVar] = pszEntry;
pIntEnv->papszEnv[iVar + 1] = NULL; /* this isn't really necessary, but doesn't hurt. */
pIntEnv->cVars = iVar + 1;
}
return rc;
}
示例4: crSaInsAt
static int crSaInsAt(CR_SORTARRAY *pArray, uint32_t iPos, uint64_t element)
{
if (pArray->cSize == pArray->cBufferSize)
{
uint32_t cNewBufferSize = pArray->cBufferSize + 16;
uint64_t *pNew;
if (pArray->pElements)
pNew = (uint64_t*)RTMemRealloc(pArray->pElements, cNewBufferSize * sizeof (pArray->pElements[0]));
else
pNew = (uint64_t*)RTMemAlloc(cNewBufferSize * sizeof (pArray->pElements[0]));
if (!pNew)
{
WARN(("no memory"));
return VERR_NO_MEMORY;
}
pArray->pElements = pNew;
pArray->cBufferSize = cNewBufferSize;
crSaValidate(pArray);
}
for (int32_t i = (int32_t)pArray->cSize - 1; i >= (int32_t)iPos; --i)
{
pArray->pElements[i+1] = pArray->pElements[i];
}
pArray->pElements[iPos] = element;
++pArray->cSize;
crSaValidate(pArray);
return VINF_SUCCESS;
}
示例5: scmStreamGrowBuffer
/**
* Grows the buffer of a write stream.
*
* @returns IPRT status code.
* @param pStream The stream. Must be in write mode.
* @param cbAppending The minimum number of bytes to grow the buffer
* with.
*/
static int scmStreamGrowBuffer(PSCMSTREAM pStream, size_t cbAppending)
{
size_t cbAllocated = pStream->cbAllocated;
cbAllocated += RT_MAX(0x1000 + cbAppending, cbAllocated);
cbAllocated = RT_ALIGN(cbAllocated, 0x1000);
void *pvNew;
if (!pStream->fFileMemory)
{
pvNew = RTMemRealloc(pStream->pch, cbAllocated);
if (!pvNew)
return pStream->rc = VERR_NO_MEMORY;
}
else
{
pvNew = RTMemDupEx(pStream->pch, pStream->off, cbAllocated - pStream->off);
if (!pvNew)
return pStream->rc = VERR_NO_MEMORY;
RTFileReadAllFree(pStream->pch, pStream->cbAllocated);
pStream->fFileMemory = false;
}
pStream->pch = (char *)pvNew;
pStream->cbAllocated = cbAllocated;
return VINF_SUCCESS;
}
示例6: vboxfuseDirInsertChild
/**
* Inserts a node into a directory
*
* The caller has locked and referenced the directory as well as checked that
* the name doesn't already exist within it. On success both the reference and
* and link counters will be incremented.
*
* @returns VBox status code.
*
* @param pDir The parent directory. Can be NULL when creating the root
* directory.
* @param pNode The node to insert.
*/
static int vboxfuseDirInsertChild(PVBOXFUSEDIR pDir, PVBOXFUSENODE pNode)
{
if (!pDir)
{
/*
* Special case: Root Directory.
*/
AssertReturn(!g_pTreeRoot, VERR_ALREADY_EXISTS);
AssertReturn(pNode->enmType == VBOXFUSETYPE_DIRECTORY, VERR_INTERNAL_ERROR);
g_pTreeRoot = (PVBOXFUSEDIR)pNode;
}
else
{
/*
* Common case.
*/
if (!(pDir->cEntries % VBOXFUSE_DIR_GROW_BY))
{
void *pvNew = RTMemRealloc(pDir->paEntries, sizeof(*pDir->paEntries) * (pDir->cEntries + VBOXFUSE_DIR_GROW_BY));
if (!pvNew)
return VERR_NO_MEMORY;
pDir->paEntries = (PVBOXFUSENODE *)pvNew;
}
pDir->paEntries[pDir->cEntries++] = pNode;
pDir->Node.cLinks++;
}
vboxfuseNodeRetain(pNode);
pNode->cLinks++;
return VINF_SUCCESS;
}
示例7: vbglR3DnDHGProcessSendDataMessages
static int vbglR3DnDHGProcessSendDataMessages(uint32_t uClientId,
uint32_t *puScreenId,
char *pszFormat,
uint32_t cbFormat,
uint32_t *pcbFormatRecv,
void **ppvData,
uint32_t cbData,
size_t *pcbDataRecv)
{
uint32_t cbDataRecv = 0;
int rc = vbglR3DnDHGProcessDataMessageInternal(uClientId,
puScreenId,
pszFormat,
cbFormat,
pcbFormatRecv,
*ppvData,
cbData,
&cbDataRecv);
size_t cbAllDataRecv = cbDataRecv;
while (rc == VERR_BUFFER_OVERFLOW)
{
uint32_t uNextMsg;
uint32_t cNextParms;
rc = vbglR3DnDQueryNextHostMessageType(uClientId, &uNextMsg, &cNextParms, false);
if (RT_SUCCESS(rc))
{
switch(uNextMsg)
{
case DragAndDropSvc::HOST_DND_HG_SND_MORE_DATA:
{
*ppvData = RTMemRealloc(*ppvData, cbAllDataRecv + cbData);
if (!*ppvData)
{
rc = VERR_NO_MEMORY;
break;
}
rc = vbglR3DnDHGProcessMoreDataMessageInternal(uClientId,
&((char*)*ppvData)[cbAllDataRecv],
cbData,
&cbDataRecv);
cbAllDataRecv += cbDataRecv;
break;
}
case DragAndDropSvc::HOST_DND_HG_EVT_CANCEL:
default:
{
rc = vbglR3DnDHGProcessCancelMessage(uClientId);
if (RT_SUCCESS(rc))
rc = VERR_CANCELLED;
break;
}
}
}
}
if (RT_SUCCESS(rc))
*pcbDataRecv = cbAllDataRecv;
return rc;
}
示例8: sbreserve
void
sbreserve(PNATState pData, struct sbuf *sb, int size)
{
NOREF(pData);
if (sb->sb_data)
{
/* Already alloced, realloc if necessary */
if (sb->sb_datalen != size)
{
sb->sb_wptr =
sb->sb_rptr =
sb->sb_data = (char *)RTMemRealloc(sb->sb_data, size);
sb->sb_cc = 0;
if (sb->sb_wptr)
sb->sb_datalen = size;
else
sb->sb_datalen = 0;
}
}
else
{
sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)RTMemAlloc(size);
sb->sb_cc = 0;
if (sb->sb_wptr)
sb->sb_datalen = size;
else
sb->sb_datalen = 0;
}
}
示例9: cpumR3MsrRangesEnsureSpace
/**
* Ensures that there is space for at least @a cNewRanges in the table,
* reallocating the table if necessary.
*
* @returns Pointer to the MSR ranges on success, NULL on failure. On failure
* @a *ppaMsrRanges is freed and set to NULL.
* @param pVM The cross context VM structure. If NULL,
* use the process heap, otherwise the VM's hyper heap.
* @param ppaMsrRanges The variable pointing to the ranges (input/output).
* @param cMsrRanges The current number of ranges.
* @param cNewRanges The number of ranges to be added.
*/
static PCPUMMSRRANGE cpumR3MsrRangesEnsureSpace(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t cMsrRanges, uint32_t cNewRanges)
{
uint32_t cMsrRangesAllocated;
if (!pVM)
cMsrRangesAllocated = RT_ALIGN_32(cMsrRanges, 16);
else
{
/*
* We're using the hyper heap now, but when the range array was copied over to it from
* the host-context heap, we only copy the exact size and not the ensured size.
* See @bugref{7270}.
*/
cMsrRangesAllocated = cMsrRanges;
}
if (cMsrRangesAllocated < cMsrRanges + cNewRanges)
{
void *pvNew;
uint32_t cNew = RT_ALIGN_32(cMsrRanges + cNewRanges, 16);
if (pVM)
{
Assert(ppaMsrRanges == &pVM->cpum.s.GuestInfo.paMsrRangesR3);
Assert(cMsrRanges == pVM->cpum.s.GuestInfo.cMsrRanges);
size_t cb = cMsrRangesAllocated * sizeof(**ppaMsrRanges);
size_t cbNew = cNew * sizeof(**ppaMsrRanges);
int rc = MMR3HyperRealloc(pVM, *ppaMsrRanges, cb, 32, MM_TAG_CPUM_MSRS, cbNew, &pvNew);
if (RT_FAILURE(rc))
{
*ppaMsrRanges = NULL;
pVM->cpum.s.GuestInfo.paMsrRangesR0 = NIL_RTR0PTR;
pVM->cpum.s.GuestInfo.paMsrRangesRC = NIL_RTRCPTR;
LogRel(("CPUM: cpumR3MsrRangesEnsureSpace: MMR3HyperRealloc failed. rc=%Rrc\n", rc));
return NULL;
}
*ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
}
else
{
pvNew = RTMemRealloc(*ppaMsrRanges, cNew * sizeof(**ppaMsrRanges));
if (!pvNew)
{
RTMemFree(*ppaMsrRanges);
*ppaMsrRanges = NULL;
return NULL;
}
}
*ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
}
if (pVM)
{
/* Update R0 and RC pointers. */
Assert(ppaMsrRanges == &pVM->cpum.s.GuestInfo.paMsrRangesR3);
pVM->cpum.s.GuestInfo.paMsrRangesR0 = MMHyperR3ToR0(pVM, *ppaMsrRanges);
pVM->cpum.s.GuestInfo.paMsrRangesRC = MMHyperR3ToRC(pVM, *ppaMsrRanges);
}
return *ppaMsrRanges;
}
示例10: vmsvga3dSaveShaderConst
int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4)
{
/* Choose a sane upper limit. */
AssertReturn(reg < _32K, VERR_INVALID_PARAMETER);
if (type == SVGA3D_SHADERTYPE_VS)
{
if (pContext->state.cVertexShaderConst <= reg)
{
pContext->state.paVertexShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paVertexShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
AssertReturn(pContext->state.paVertexShaderConst, VERR_NO_MEMORY);
for (uint32_t i = pContext->state.cVertexShaderConst; i < reg + 1; i++)
pContext->state.paVertexShaderConst[i].fValid = false;
pContext->state.cVertexShaderConst = reg + 1;
}
pContext->state.paVertexShaderConst[reg].fValid = true;
pContext->state.paVertexShaderConst[reg].ctype = ctype;
pContext->state.paVertexShaderConst[reg].value[0] = val1;
pContext->state.paVertexShaderConst[reg].value[1] = val2;
pContext->state.paVertexShaderConst[reg].value[2] = val3;
pContext->state.paVertexShaderConst[reg].value[3] = val4;
}
else
{
Assert(type == SVGA3D_SHADERTYPE_PS);
if (pContext->state.cPixelShaderConst <= reg)
{
pContext->state.paPixelShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paPixelShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
AssertReturn(pContext->state.paPixelShaderConst, VERR_NO_MEMORY);
for (uint32_t i = pContext->state.cPixelShaderConst; i < reg + 1; i++)
pContext->state.paPixelShaderConst[i].fValid = false;
pContext->state.cPixelShaderConst = reg + 1;
}
pContext->state.paPixelShaderConst[reg].fValid = true;
pContext->state.paPixelShaderConst[reg].ctype = ctype;
pContext->state.paPixelShaderConst[reg].value[0] = val1;
pContext->state.paPixelShaderConst[reg].value[1] = val2;
pContext->state.paPixelShaderConst[reg].value[2] = val3;
pContext->state.paPixelShaderConst[reg].value[3] = val4;
}
return VINF_SUCCESS;
}
示例11: VDMemDiskSetSize
int VDMemDiskSetSize(PVDMEMDISK pMemDisk, uint64_t cbSize)
{
AssertPtrReturn(pMemDisk, VERR_INVALID_POINTER);
if (!pMemDisk->fGrowable)
return VERR_NOT_SUPPORTED;
if (pMemDisk->cbDisk <= cbSize)
{
/* Increase. */
pMemDisk->cbDisk = cbSize;
}
else
{
/* We have to delete all parts beyond the new end. */
PVDMEMDISKSEG pSeg = (PVDMEMDISKSEG)RTAvlrU64Get(pMemDisk->pTreeSegments, cbSize);
if (pSeg)
{
RTAvlrU64Remove(pMemDisk->pTreeSegments, pSeg->Core.Key);
if (pSeg->Core.Key < cbSize)
{
/* Cut off the part which is not in the file anymore. */
pSeg->pvSeg = RTMemRealloc(pSeg->pvSeg, pSeg->Core.KeyLast - cbSize + 1);
pSeg->Core.KeyLast = cbSize - pSeg->Core.Key - 1;
bool fInserted = RTAvlrU64Insert(pMemDisk->pTreeSegments, &pSeg->Core);
AssertMsg(fInserted, ("Bug!\n"));
}
else
{
/* Free the whole block. */
RTMemFree(pSeg->pvSeg);
RTMemFree(pSeg);
}
}
/* Kill all blocks coming after. */
do
{
pSeg = (PVDMEMDISKSEG)RTAvlrU64GetBestFit(pMemDisk->pTreeSegments, cbSize, true);
if (pSeg)
{
RTAvlrU64Remove(pMemDisk->pTreeSegments, pSeg->Core.Key);
RTMemFree(pSeg->pvSeg);
pSeg->pvSeg = NULL;
RTMemFree(pSeg);
}
else
break;
} while (true);
pMemDisk->cbDisk = cbSize;
}
return VINF_SUCCESS;
}
示例12: ScmSvnSetProperty
/**
* Schedules the setting of a property.
*
* @returns IPRT status code.
* @retval VERR_INVALID_STATE if not a SVN WC file.
* @param pState The rewrite state to work on.
* @param pszName The name of the property to set.
* @param pszValue The value. NULL means deleting it.
*/
int ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue)
{
/*
* Update any existing entry first.
*/
size_t i = pState->cSvnPropChanges;
while (i-- > 0)
if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
{
if (!pszValue)
{
RTStrFree(pState->paSvnPropChanges[i].pszValue);
pState->paSvnPropChanges[i].pszValue = NULL;
}
else
{
char *pszCopy;
int rc = RTStrDupEx(&pszCopy, pszValue);
if (RT_FAILURE(rc))
return rc;
pState->paSvnPropChanges[i].pszValue = pszCopy;
}
return VINF_SUCCESS;
}
/*
* Insert a new entry.
*/
i = pState->cSvnPropChanges;
if ((i % 32) == 0)
{
void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP));
if (!pvNew)
return VERR_NO_MEMORY;
pState->paSvnPropChanges = (PSCMSVNPROP)pvNew;
}
pState->paSvnPropChanges[i].pszName = RTStrDup(pszName);
pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL;
if ( pState->paSvnPropChanges[i].pszName
&& (pState->paSvnPropChanges[i].pszValue || !pszValue) )
pState->cSvnPropChanges = i + 1;
else
{
RTStrFree(pState->paSvnPropChanges[i].pszName);
pState->paSvnPropChanges[i].pszName = NULL;
RTStrFree(pState->paSvnPropChanges[i].pszValue);
pState->paSvnPropChanges[i].pszValue = NULL;
return VERR_NO_MEMORY;
}
return VINF_SUCCESS;
}
示例13: scmStreamGrowLines
/**
* Grows the line array of a stream.
*
* @returns IPRT status code.
* @param pStream The stream.
* @param iMinLine Minimum line number.
*/
static int scmStreamGrowLines(PSCMSTREAM pStream, size_t iMinLine)
{
size_t cLinesAllocated = pStream->cLinesAllocated;
cLinesAllocated += RT_MAX(512 + iMinLine, cLinesAllocated);
cLinesAllocated = RT_ALIGN(cLinesAllocated, 512);
void *pvNew = RTMemRealloc(pStream->paLines, cLinesAllocated * sizeof(SCMSTREAMLINE));
if (!pvNew)
return pStream->rc = VERR_NO_MEMORY;
pStream->paLines = (PSCMSTREAMLINE)pvNew;
pStream->cLinesAllocated = cLinesAllocated;
return VINF_SUCCESS;
}
示例14: rtS3WriteMemoryCallback
static size_t rtS3WriteMemoryCallback(void *pvBuf, size_t cSize, size_t cBSize, void *pvUser)
{
PRTS3TMPMEMCHUNK pTmpMem = (PRTS3TMPMEMCHUNK)pvUser;
size_t cRSize = cSize * cBSize;
pTmpMem->pszMem = (char*)RTMemRealloc(pTmpMem->pszMem, pTmpMem->cSize + cRSize + 1);
if (pTmpMem->pszMem)
{
memcpy(&(pTmpMem->pszMem[pTmpMem->cSize]), pvBuf, cRSize);
pTmpMem->cSize += cRSize;
pTmpMem->pszMem[pTmpMem->cSize] = 0;
}
return cRSize;
}
示例15: DECLCALLBACK
static DECLCALLBACK(size_t) rtHttpWriteData(void *pvBuf, size_t cb, size_t n, void *pvUser)
{
PRTHTTPMEMCHUNK pMem = (PRTHTTPMEMCHUNK)pvUser;
size_t cbAll = cb * n;
pMem->pu8Mem = (uint8_t*)RTMemRealloc(pMem->pu8Mem, pMem->cb + cbAll + 1);
if (pMem->pu8Mem)
{
memcpy(&pMem->pu8Mem[pMem->cb], pvBuf, cbAll);
pMem->cb += cbAll;
pMem->pu8Mem[pMem->cb] = '\0';
}
return cbAll;
}