provide g_newa(ctype, count) on top of g_alloca() like we provide g_new()
authorTim Janik <timj@gtk.org>
Wed, 14 Nov 2001 07:50:12 +0000 (07:50 +0000)
committerTim Janik <timj@src.gnome.org>
Wed, 14 Nov 2001 07:50:12 +0000 (07:50 +0000)
Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>

        * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
        g_alloca() like we provide g_new() on top of g_malloc().

14 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
Makefile.am
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/memory.sgml
docs/reference/glib/tmpl/spawn.sgml
docs/reference/glib/tmpl/unicode.sgml
glib/galloca.h

index cc85f5d..47c00a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index cc85f5d..47c00a9 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 14 07:34:24 2001  Tim Janik  <timj@gtk.org>
+
+       * glib/galloca.h (g_newa): provide g_newa(ctype, count) on top of
+       g_alloca() like we provide g_new() on top of g_malloc().
+
 Tue Nov 13 21:25:35 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gen-unicode-tables.pl,gunibreak.c,gunibreak.h,
index bd402b7..31c8d69 100644 (file)
@@ -2,7 +2,7 @@
 
 AUTOMAKE_OPTIONS = 1.4
 
-SUBDIRS = . m4macros glib gobject gmodule gthread docs tests build po
+SUBDIRS = . m4macros glib gobject gmodule gthread tests build po docs
 
 bin_SCRIPTS = glib-gettextize
 
index 34d5112..55c0996 100644 (file)
@@ -697,6 +697,7 @@ g_free
 
 <SUBSECTION>
 g_alloca
+g_newa
 
 <SUBSECTION>
 g_memmove
index ee61d66..b20aa3f 100644 (file)
@@ -124,10 +124,51 @@ If @mem is %NULL it simply returns.
 <!-- ##### MACRO g_alloca ##### -->
 <para>
 Allocates @size bytes on the stack; these bytes will be freed when the current
-stack frame is cleaned up.
+stack frame is cleaned up. This macro essentially just wraps the alloca(3) function
+present on most unix variants. Thus it provides the same advantages and pitfalls
+as alloca():
+<msgtext><variablelist>
+  <varlistentry><term></term><listitem><para>
+    + alloca() is very fast, as on most systems it's implemented by just adjusting
+    the stack pointer register.
+  </para></listitem></varlistentry>
+  <varlistentry><term></term><listitem><para>
+    + It doesn't cause any memory fragmentation, within its scope, seperate alloca()
+    blocks just build up and are released together at function end.
+  </para></listitem></varlistentry>
+  <varlistentry><term></term><listitem><para>
+    - Allocation sizes have to fit into the current stack frame. For instance in a
+      threaded environment on Linux, the per-thread stack size is limited to 2 Megabytes,
+      so be sparse with alloca() uses.
+  </para></listitem></varlistentry>
+  <varlistentry><term></term><listitem><para>
+    - Allocation failure due to insufficient stack space is not indicated with a %NULL
+      return like e.g. with malloc(3). Instead, most systems probably handle it the same
+      way as out of stack space situations from infinite function recursion, i.e.
+      with a segmentation fault.
+  </para></listitem></varlistentry>
+  <varlistentry><term></term><listitem><para>
+    - Special care has to be taken when mixing alloca(3) with GCC variable sized arrays.
+      Stack space allocated with alloca(3) in the same scope as a variable sized array
+      will be freed together with the variable sized array upon exit of that scope, and
+      not upon exit of the enclosing function scope.
+  </para></listitem></varlistentry>
+</variablelist></msgtext>
+
+</para>
+
+@size:    number of bytes to allocate.
+@Returns: space for @size bytes, allocated on the stack
+
+
+<!-- ##### MACRO g_newa ##### -->
+<para>
+Wraps g_alloca() in a more typesafe manner.
 </para>
 
-@size: number of bytes to allocate.
+@struct_type: Type of memory chunks to be allocated
+@n_structs:   Number of chunks to be allocated
+@Returns:     Pointer to stack space for @n_structs chunks of type @struct_type
 
 
 <!-- ##### MACRO g_memmove ##### -->
index 633a93b..9426a77 100644 (file)
@@ -56,7 +56,7 @@ Flags passed to g_spawn_sync(), g_spawn_async() and g_spawn_async_with_pipes().
 
 @G_SPAWN_LEAVE_DESCRIPTORS_OPEN: the parent's open file descriptors will be 
  inherited by the child; otherwise all descriptors except stdin/stdout/stderr 
- will be closed before calling <function>exec()</function> in the child. 
+ will be closed before calling <function>exec()</function> in the child.
 @G_SPAWN_DO_NOT_REAP_CHILD: the child will not be automatically reaped; you 
   must call <function>waitpid()</function> or handle <literal>SIGCHLD</literal> 
   yourself, or the child will become a zombie.
index fabf29d..1bab836 100644 (file)
@@ -518,20 +518,20 @@ character. Unicode strings should generally be normalized before comparing them.
 </para>
 
 @G_NORMALIZE_DEFAULT: standardize differences that do not affect the
-  text content, such as the above-mentioned accent representation.  
-@G_NORMALIZE_NFD: another name for %G_NORMALIZE_DEFAULT. 
+  text content, such as the above-mentioned accent representation.
+@G_NORMALIZE_NFD: another name for %G_NORMALIZE_DEFAULT.
 @G_NORMALIZE_DEFAULT_COMPOSE: like %G_NORMALIZE_DEFAULT, but with composed
-  forms rather than a maximally decomposed form. 
+  forms rather than a maximally decomposed form.
 @G_NORMALIZE_NFC: another name for %G_NORMALIZE_DEFAULT_COMPOSE.
 @G_NORMALIZE_ALL: beyond %G_NORMALIZE_DEFAULT also standardize the 
   "compatibility" characters in Unicode, such as SUPERSCRIPT THREE to the 
   standard forms (in this case DIGIT THREE). Formatting information may be 
   lost but for most text operations such characters should be considered the 
-  same. 
-@G_NORMALIZE_NFKD: another name for %G_NORMALIZE_ALL. 
+  same.
+@G_NORMALIZE_NFKD: another name for %G_NORMALIZE_ALL.
 @G_NORMALIZE_ALL_COMPOSE: like %G_NORMALIZE_ALL, but with composed
-  forms rather than a maximally decomposed form. 
-@G_NORMALIZE_NFKC: another name for %G_NORMALIZE_ALL_COMPOSE. 
+  forms rather than a maximally decomposed form.
+@G_NORMALIZE_NFKC: another name for %G_NORMALIZE_ALL_COMPOSE.
 
 <!-- ##### FUNCTION g_utf8_collate ##### -->
 <para>
index 7bc0a5f..571ab76 100644 (file)
@@ -53,8 +53,8 @@ G_END_DECLS
 # endif /* !_MSC_VER */
 #endif /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
 
-#define g_alloca(size) alloca (size)
+#define g_alloca(size)          alloca (size)
+#define g_newa(struct_type, n_structs) ((struct_type*) g_alloca (sizeof (struct_type) * (gsize) (n_structs)))
 
 
 #endif /* __G_ALLOCA_H__ */
-