From 943a12613f6174f8c78f8e7156efa0f22c5e6f06 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Fri, 16 Mar 2007 16:53:33 +0000 Subject: [PATCH] + memb_inmemb --- core/lib/memb.c | 9 ++++++++- core/lib/memb.h | 15 +++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/lib/memb.c b/core/lib/memb.c index e14e6085f..a599bd67d 100644 --- a/core/lib/memb.c +++ b/core/lib/memb.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: memb.c,v 1.2 2006/08/16 22:12:46 oliverschmidt Exp $ + * $Id: memb.c,v 1.3 2007/03/16 16:53:33 adamdunkels Exp $ */ /** @@ -101,5 +101,12 @@ memb_free(struct memb_blocks *m, void *ptr) return -1; } /*---------------------------------------------------------------------------*/ +int +memb_inmemb(struct memb_blocks *m, void *ptr) +{ + return (char *)ptr >= (char *)m->mem && + (char *)ptr < (char *)m->mem + (m->num * m->size); +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/core/lib/memb.h b/core/lib/memb.h index 0b533f155..e579e60c9 100644 --- a/core/lib/memb.h +++ b/core/lib/memb.h @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: memb.h,v 1.1 2006/06/17 22:41:18 adamdunkels Exp $ + * $Id: memb.h,v 1.2 2007/03/16 16:53:33 adamdunkels Exp $ */ /** @@ -49,14 +49,6 @@ * memory by the memb_alloc() function, and are deallocated with the * memb_free() function. * - * \note Because of namespace clashes only one MEMB() can be - * declared per C module, and the name scope of a MEMB() memory - * block is local to each C module. - * - * The following example shows how to declare and use a memory block - * called "cmem" which has 8 chunks of memory with each memory chunk - * being 20 bytes large. - * * @{ */ @@ -90,7 +82,7 @@ * * Example: \code -MEMB(connections, sizeof(struct connection), 16); +MEMB(connections, struct connection, 16); \endcode * * \param name The name of the memory block (later used with @@ -143,6 +135,9 @@ void *memb_alloc(struct memb_blocks *m); */ char memb_free(struct memb_blocks *m, void *ptr); +int memb_inmemb(struct memb_blocks *m, void *ptr); + + /** @} */ /** @} */