From 1cf6842543cbbea5564d2908791f3251c60f3d73 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 31 Oct 2015 05:01:07 +0100 Subject: doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/slibc-alloc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/slibc-alloc.c') diff --git a/src/slibc-alloc.c b/src/slibc-alloc.c index 604eff1..a7ae30a 100644 --- a/src/slibc-alloc.c +++ b/src/slibc-alloc.c @@ -25,8 +25,31 @@ +/** + * Get the alignment-shift of a pointer. + * + * @param p:void* The pointer. + * @return :size_t The number of bytes added for alignment. + * This excludes the information this macro + * reads, and the storage of the allocation-size. + */ #define __ALIGN(p) (*(size_t*)(((char*)(p)) - sizeof(size_t))) + +/** + * Get the allocated pointer from a returned pointer. + * + * @param p:void* The pointer returned by a `malloc`-family function. + * @return The pointer allocated by a `malloc`-family function. + */ #define PURE_ALLOC(p) (((char*)(p)) - (__ALIGN(p) + 2 * sizeof(size_t))) + +/** + * Get the real allocation is of a pointer, including + * the size of the metadata storage and the alignment-padding. + * + * @param p:void* The pointer. + * @return :size_t The real allocation size of the pointer. + */ #define PURE_SIZE(p) (*(size_t*)PURE_ALLOC(p) + 2 * sizeof(size_t)) -- cgit v1.2.3-70-g09d2