X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/43f490c377cb05d1ac6e7d2c27a06ae940e2c047..a077a9a931a4b81abf0f549d7f463ae75075149a:/mem/sub.h diff --git a/mem/sub.h b/mem/sub.h index 1dddd19..661341e 100644 --- a/mem/sub.h +++ b/mem/sub.h @@ -168,6 +168,21 @@ extern void subarena_free(subarena */*s*/, void */*p*/, size_t /*sz*/); #define A_CREATE(a, type) subarena_alloc((a), sizeof(type)) +/* --- @A_SUBNEW@ --- * + * + * Arguments: @type *p@ = a pointer to allocate + * @subarena *s@ = pointer to arena + * + * Returns: --- + * + * Use: Set @p@ to point to a freshly allocated block large enough to + * hold an object of the type pointed to by @p@. If there is + * not enough memory, the exception @EXC_NOMEM@ is thrown. + */ + +#define A_SUBNEW(p, a) \ + do { (p) = subarena_alloc((a), sizeof(*(p))); } while (0) + /* --- @A_DESTROY@ --- * * * Arguments: @subarena *s@ = pointer to arena @@ -220,6 +235,19 @@ extern void sub_free(void */*p*/, size_t /*sz*/); #define CREATE(type) sub_alloc(sizeof(type)) +/* --- @NEW@ --- * + * + * Arguments: @type *p@ = a pointer to allocate + * + * Returns: --- + * + * Use: Set @p@ to point to a freshly allocated block large enough to + * hold an object of the type pointed to by @p@. If there is + * not enough memory, the exception @EXC_NOMEM@ is thrown. + */ + +#define NEW(p) do { (p) = sub_alloc(sizeof(*(p))); } while (0) + /* --- @DESTROY@ --- * * * Arguments: @void *p@ = pointer to an object