mpllite functions for maxmem/freemem compatibility

This commit is contained in:
Kelvin Sherlock 2013-03-30 18:44:39 -04:00
parent 3f5efae581
commit 6f93bd0826
2 changed files with 55 additions and 0 deletions

View File

@ -189,6 +189,54 @@ MPLITE_API int mplite_resize(mplite_t *handle, const void *pPrior,
return MPLITE_ERR_INVPAR; // not really, but ok.
}
/* return the largest available block size */
MPLITE_API int mplite_maxmem(mplite_t *handle)
{
unsigned i;
if (NULL == handle) return 0;
mplite_enter(handle);
for (i = MPLITE_LOGMAX + 1; i; --i)
{
if (handle->aiFreelist[i - 1] != -1) break;
}
mplite_leave(handle);
if (i) return (1 << (i - 1)) * handle->szAtom;
else return 0;
}
/* return the total available memory */
MPLITE_API int mplite_freemem(mplite_t *handle)
{
int total;
int blocksize;
int i;
if (NULL == handle) return 0;
total = 0;
mplite_enter(handle);
for (i = 0, blocksize = 1; i <= MPLITE_LOGMAX; ++i, blocksize <<= 1)
{
int index = handle->aiFreelist[i];
while (index != -1)
{
mplite_link_t *link = mplite_getlink(handle, index);
total += blocksize;
index = link->next;
}
}
mplite_leave(handle);
return total * handle->szAtom;
//return handle->szAtom * handle->nBlock - handle->currentOut;
}
MPLITE_API int mplite_roundup(mplite_t *handle, const int n)
{
int iFullSz;

View File

@ -220,6 +220,13 @@ MPLITE_API void mplite_print_stats(const mplite_t * const handle,
*/
#define mplite_alloc_count(handle) (((handle) != NULL)? (handle)->nAlloc : 0)
/* return the largest available block size */
MPLITE_API int mplite_maxmem(mplite_t *handle);
/* return the total available memory */
MPLITE_API int mplite_freemem(mplite_t *handle);
#ifdef __cplusplus
}
#endif