From dd7a6d98620a2aca6914ae4430182f49cd5c571b Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 15 Feb 2013 19:26:59 -0500 Subject: [PATCH] mplite_resize (in-place realloc) --- mplite/mplite.c | 21 +++++++++++++++++++++ mplite/mplite.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/mplite/mplite.c b/mplite/mplite.c index 7e21524..cc6b371 100644 --- a/mplite/mplite.c +++ b/mplite/mplite.c @@ -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; diff --git a/mplite/mplite.h b/mplite/mplite.h index 34e3980..76fb485 100644 --- a/mplite/mplite.h +++ b/mplite/mplite.h @@ -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