本文整理汇总了C++中RTMemRealloc函数的典型用法代码示例。如果您正苦于以下问题:C++ RTMemRealloc函数的具体用法?C++ RTMemRealloc怎么用?C++ RTMemRealloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTMemRealloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:28,代码来源:DisplayPNGUtil.cpp
示例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;
}
开发者ID:mcenirm,项目名称:vbox,代码行数:33,代码来源:VUSBSniffer.cpp
示例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;
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:39,代码来源:env-generic.cpp
示例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;
}
开发者ID:gvsurenderreddy,项目名称:virtualbox,代码行数:33,代码来源:sortarray.cpp
示例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;
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:33,代码来源:scmstream.cpp
示例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;
}
开发者ID:leopucci,项目名称:VirtualMonitor,代码行数:44,代码来源:VBoxFUSE.cpp
示例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;
}
开发者ID:OSLL,项目名称:vboxhsm,代码行数:60,代码来源:VBoxGuestR3LibDragAndDrop.cpp
示例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;
}
}
开发者ID:zBMNForks,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:29,代码来源:sbuf.c
示例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;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:71,代码来源:CPUMR3Db.cpp
示例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;
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:46,代码来源:DevVGA-SVGA3d-savedstate.cpp
示例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;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:56,代码来源:VDMemDisk.cpp
示例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;
}
开发者ID:bringhurst,项目名称:vbox,代码行数:61,代码来源:scmsubversion.cpp
示例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;
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:20,代码来源:scmstream.cpp
示例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;
}
开发者ID:mcenirm,项目名称:vbox,代码行数:14,代码来源:s3.cpp
示例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;
}
开发者ID:Klanly,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:14,代码来源:http.cpp
示例16: tstMemAutoPtrDisas1PureC
/*
* For comparing to tstMemAutoPtrDisas1.
*/
extern "C" int tstMemAutoPtrDisas1PureC(void **ppv)
{
TSTMEMAUTOPTRSTRUCT *pHandle = (TSTMEMAUTOPTRSTRUCT *)RTMemRealloc(NULL, sizeof(*pHandle));
if (pHandle)
{
pHandle->a = RTRandU32();
if (pHandle->a < UINT32_MAX / 2)
{
*ppv = pHandle;
return VINF_SUCCESS;
}
RTMemFree(pHandle);
}
return VERR_TRY_AGAIN;
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:18,代码来源:tstMemAutoPtr.cpp
示例17: DECLCALLBACK
/** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnRealloc} */
static DECLCALLBACK(int) rtAsn1DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
void *pvOld, void **ppvNew, size_t cbNew)
{
Assert(pvOld);
Assert(cbNew);
size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cbNew);
void *pv = RTMemRealloc(pvOld, cbAlloc);
if (pv)
{
*ppvNew = pv;
pAllocation->cbAllocated = (uint32_t)cbAlloc;
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:16,代码来源:asn1-default-allocator.cpp
示例18: pam_vbox_wait_prop
/**
* Waits for a guest property to be changed.
*
* @return IPRT status code.
* @param hPAM PAM handle.
* @param uClientID Guest property service client ID.
* @param pszKey Key (name) of guest property to wait for.
* @param uTimeoutMS Timeout (in ms) to wait for the change. Specify
* RT_INDEFINITE_WAIT to wait indefinitly.
*/
static int pam_vbox_wait_prop(pam_handle_t *hPAM, uint32_t uClientID,
const char *pszKey, uint32_t uTimeoutMS)
{
AssertPtrReturn(hPAM, VERR_INVALID_POINTER);
AssertReturn(uClientID, VERR_INVALID_PARAMETER);
AssertPtrReturn(pszKey, VERR_INVALID_POINTER);
int rc;
/* The buffer for storing the data and its initial size. We leave a bit
* of space here in case the maximum values are raised. */
void *pvBuf = NULL;
uint32_t cbBuf = GUEST_PROP_MAX_NAME_LEN + GUEST_PROP_MAX_VALUE_LEN + GUEST_PROP_MAX_FLAGS_LEN + _1K;
for (int i = 0; i < 10; i++)
{
void *pvTmpBuf = RTMemRealloc(pvBuf, cbBuf);
if (pvTmpBuf)
{
char *pszName = NULL;
char *pszValue = NULL;
uint64_t u64TimestampOut = 0;
char *pszFlags = NULL;
pvBuf = pvTmpBuf;
rc = VbglR3GuestPropWait(uClientID, pszKey, pvBuf, cbBuf,
0 /* Last timestamp; just wait for next event */, uTimeoutMS,
&pszName, &pszValue, &u64TimestampOut,
&pszFlags, &cbBuf);
}
else
rc = VERR_NO_MEMORY;
if (rc == VERR_BUFFER_OVERFLOW)
{
/* Buffer too small, try it with a bigger one next time. */
cbBuf += _1K;
continue; /* Try next round. */
}
/* Everything except VERR_BUFFER_OVERLOW makes us bail out ... */
break;
}
return rc;
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:56,代码来源:pam_vbox.cpp
示例19: 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 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(PCPUMMSRRANGE *ppaMsrRanges, uint32_t cMsrRanges, uint32_t cNewRanges)
{
uint32_t cMsrRangesAllocated = RT_ALIGN_32(cMsrRanges, 16);
if (cMsrRangesAllocated < cMsrRanges + cNewRanges)
{
uint32_t cNew = RT_ALIGN_32(cMsrRanges + cNewRanges, 16);
void *pvNew = RTMemRealloc(*ppaMsrRanges, cNew * sizeof(**ppaMsrRanges));
if (!pvNew)
{
RTMemFree(*ppaMsrRanges);
*ppaMsrRanges = NULL;
return NULL;
}
*ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
}
return *ppaMsrRanges;
}
开发者ID:gvsurenderreddy,项目名称:virtualbox,代码行数:27,代码来源:CPUMR3Db.cpp
示例20: VBOXDBGCONSOLE_FROM_DBGCBACK
VBoxDbgConsole::backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
{
VBoxDbgConsole *pThis = VBOXDBGCONSOLE_FROM_DBGCBACK(pBack);
int rc = VINF_SUCCESS;
pThis->lock();
if (cbBuf + pThis->m_cbOutputBuf >= pThis->m_cbOutputBufAlloc)
{
size_t cbNew = RT_ALIGN_Z(cbBuf + pThis->m_cbOutputBufAlloc + 1, 1024);
void *pv = RTMemRealloc(pThis->m_pszOutputBuf, cbNew);
if (!pv)
{
pThis->unlock();
if (pcbWritten)
*pcbWritten = 0;
return VERR_NO_MEMORY;
}
pThis->m_pszOutputBuf = (char *)pv;
pThis->m_cbOutputBufAlloc = cbNew;
}
/*
* Add the output.
*/
memcpy(pThis->m_pszOutputBuf + pThis->m_cbOutputBuf, pvBuf, cbBuf);
pThis->m_cbOutputBuf += cbBuf;
pThis->m_pszOutputBuf[pThis->m_cbOutputBuf] = '\0';
if (pcbWritten)
*pcbWritten = cbBuf;
if (ASMAtomicUoReadBool(&pThis->m_fTerminate))
rc = VERR_GENERAL_FAILURE;
/*
* Tell the GUI thread to draw this text.
* We cannot do it from here without frequent crashes.
*/
if (!pThis->m_fUpdatePending)
QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kUpdate));
pThis->unlock();
return rc;
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:44,代码来源:VBoxDbgConsole.cpp
注:本文中的RTMemRealloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论