Add nallocm().

Add nallocm(), which computes the real allocation size that would result
from the corresponding allocm() call.  nallocm() is a functional
superset of OS X's malloc_good_size(), in that it takes alignment
constraints into account.
This commit is contained in:
Jason Evans
2012-02-29 12:56:37 -08:00
parent 4bb0983013
commit 7e15dab94d
5 changed files with 131 additions and 25 deletions

View File

@@ -1586,6 +1586,28 @@ JEMALLOC_P(dallocm)(void *ptr, int flags)
return (ALLOCM_SUCCESS);
}
JEMALLOC_ATTR(visibility("default"))
int
JEMALLOC_P(nallocm)(size_t *rsize, size_t size, int flags)
{
size_t usize;
size_t alignment = (ZU(1) << (flags & ALLOCM_LG_ALIGN_MASK)
& (SIZE_T_MAX-1));
assert(size != 0);
if (malloc_init())
return (ALLOCM_ERR_OOM);
usize = (alignment == 0) ? s2u(size) : sa2u(size, alignment, NULL);
if (usize == 0)
return (ALLOCM_ERR_OOM);
if (rsize != NULL)
*rsize = usize;
return (ALLOCM_SUCCESS);
}
/*
* End non-standard functions.
*/