Drop the GMenu markup functions
[glib.git] / glib / galloca.h
blob1ecdf65c042caf66c0421f9bdcbb541087ff286a
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
31 #ifndef __G_ALLOCA_H__
32 #define __G_ALLOCA_H__
34 #include <glib/gtypes.h>
36 #ifdef __GNUC__
37 /* GCC does the right thing */
38 # undef alloca
39 # define alloca(size) __builtin_alloca (size)
40 #elif defined (GLIB_HAVE_ALLOCA_H)
41 /* a native and working alloca.h is there */
42 # include <alloca.h>
43 #else /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
44 # if defined(_MSC_VER) || defined(__DMC__)
45 # include <malloc.h>
46 # define alloca _alloca
47 # else /* !_MSC_VER && !__DMC__ */
48 # ifdef _AIX
49 # pragma alloca
50 # else /* !_AIX */
51 # ifndef alloca /* predefined by HP cc +Olibcalls */
52 G_BEGIN_DECLS
53 char *alloca ();
54 G_END_DECLS
55 # endif /* !alloca */
56 # endif /* !_AIX */
57 # endif /* !_MSC_VER && !__DMC__ */
58 #endif /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
60 /**
61 * g_alloca:
62 * @size: number of bytes to allocate.
64 * Allocates @size bytes on the stack; these bytes will be freed when the current
65 * stack frame is cleaned up. This macro essentially just wraps the alloca()
66 * function present on most UNIX variants.
67 * Thus it provides the same advantages and pitfalls as alloca():
68 * <variablelist>
69 * <varlistentry><term></term><listitem><para>
70 * + alloca() is very fast, as on most systems it's implemented by just adjusting
71 * the stack pointer register.
72 * </para></listitem></varlistentry>
73 * <varlistentry><term></term><listitem><para>
74 * + It doesn't cause any memory fragmentation, within its scope, separate alloca()
75 * blocks just build up and are released together at function end.
76 * </para></listitem></varlistentry>
77 * <varlistentry><term></term><listitem><para>
78 * - Allocation sizes have to fit into the current stack frame. For instance in a
79 * threaded environment on Linux, the per-thread stack size is limited to 2 Megabytes,
80 * so be sparse with alloca() uses.
81 * </para></listitem></varlistentry>
82 * <varlistentry><term></term><listitem><para>
83 * - Allocation failure due to insufficient stack space is not indicated with a %NULL
84 * return like e.g. with malloc(). Instead, most systems probably handle it the same
85 * way as out of stack space situations from infinite function recursion, i.e.
86 * with a segmentation fault.
87 * </para></listitem></varlistentry>
88 * <varlistentry><term></term><listitem><para>
89 * - Special care has to be taken when mixing alloca() with GNU C variable sized arrays.
90 * Stack space allocated with alloca() in the same scope as a variable sized array
91 * will be freed together with the variable sized array upon exit of that scope, and
92 * not upon exit of the enclosing function scope.
93 * </para></listitem></varlistentry>
94 * </variablelist>
96 * Returns: space for @size bytes, allocated on the stack
98 #define g_alloca(size) alloca (size)
99 /**
100 * g_newa:
101 * @struct_type: Type of memory chunks to be allocated
102 * @n_structs: Number of chunks to be allocated
104 * Wraps g_alloca() in a more typesafe manner.
106 * Returns: Pointer to stack space for @n_structs chunks of type @struct_type
108 #define g_newa(struct_type, n_structs) ((struct_type*) g_alloca (sizeof (struct_type) * (gsize) (n_structs)))
110 #endif /* __G_ALLOCA_H__ */