chiark / gitweb /
@@@ tvec and tty mess
[mLib] / mem / sub.h
index 1dddd194b1f10217e0d9856b96d889f320697421..661341e52f78d571644f01a77aa83ddfcb288870 100644 (file)
--- 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