mplite_resize (in-place realloc)

This commit is contained in:
Kelvin Sherlock 2013-02-15 19:26:59 -05:00
parent 3c65212ba3
commit dd7a6d9862
2 changed files with 26 additions and 0 deletions

View File

@ -168,6 +168,27 @@ MPLITE_API void *mplite_realloc(mplite_t *handle, const void *pPrior,
return p;
}
// like realloc but will not resize.
// for compatibility with MM::SetPtrSize
MPLITE_API int mplite_resize(mplite_t *handle, const void *pPrior,
const int nBytes)
{
int nOld;
/* Check the parameters */
if ((NULL == handle) || (NULL == pPrior) || (nBytes <= 0) ||
(nBytes & (nBytes - 1))) {
return MPLITE_ERR_INVPAR;
}
nOld = mplite_size(handle, pPrior);
if (nBytes <= nOld) {
return MPLITE_OK;
}
return MPLITE_ERR_INVPAR; // not really, but ok.
}
MPLITE_API int mplite_roundup(mplite_t *handle, const int n)
{
int iFullSz;

View File

@ -192,6 +192,11 @@ MPLITE_API void mplite_free(mplite_t *handle, const void *pPrior);
MPLITE_API void *mplite_realloc(mplite_t *handle, const void *pPrior,
const int nBytes);
MPLITE_API int mplite_resize(mplite_t *handle, const void *pPrior,
const int nBytes);
/**
* @brief Round up a request size to the next valid allocation size.
* @param[in,out] handle Pointer to an initialized @ref mplite_t object