5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1999 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/SILC Memory Interface
24 * Basic utility functions for allocating memory. All SILC routines, and
25 * applications use these functions when they need to allocate, manipulate
28 * Currently all allocation routines assert() that the memory was allocated
29 * successfully. Hence, if memory allocation fails it is fatal error.
38 #ifndef SILC_STACKTRACE
40 /****f* silcutil/SilcMemoryAPI/silc_malloc
44 * void *silc_malloc(size_t size);
48 * Allocates memory of `size' bytes and returns pointer to the allocated
49 * memory area. Free the memory by calling silc_free.
52 void *silc_malloc(size_t size);
54 /****f* silcutil/SilcMemoryAPI/silc_calloc
58 * void *silc_calloc(size_t items, size_t size);
62 * Allocates memory of for an array of `items' elements of `size' bytes
63 * and returns pointer to the allocated memory area. The memory area is
64 * also zeroed. Free the memory by calling silc_free.
67 void *silc_calloc(size_t items, size_t size);
69 /****f* silcutil/SilcMemoryAPI/silc_realloc
73 * void *silc_realloc(void *ptr, size_t size);
77 * Change the size of the memory block indicated by `ptr' to the new
78 * size of `size' bytes. The contents of `ptr' will not be changed.
79 * If `ptr' is NULL the call is equivalent to silc_malloc. If the
80 * `size' is zero (0) the call is equivalent to silc_free. Free the
81 * memory by calling silc_free.
85 * The pointer returned to the reallocated memory area might not be
89 void *silc_realloc(void *ptr, size_t size);
91 /****f* silcutil/SilcMemoryAPI/silc_free
95 * void silc_free(void *ptr);
99 * Frees the memory area indicated by the `ptr'. If `ptr' is NULL no
100 * operation is performed.
103 void silc_free(void *ptr);
105 /****f* silcutil/SilcMemoryAPI/silc_memdup
109 * void *silc_memdup(const void *ptr, size_t size);
113 * Duplicates the memory area indicated by `ptr' which is of size
114 * of `size' bytes. Returns pointer to the duplicated memory area.
115 * This NULL terminates the dupped memory area by allocating `size' + 1
116 * bytes, so this function can be used to duplicate strings that does
117 * not have NULL termination.
120 void *silc_memdup(const void *ptr, size_t size);
123 #ifndef SILC_DIST_TOOLKIT
124 #error "The stack trace is not supported in this distribution"
127 #include "stacktrace.h"
128 #endif /* SILC_STACKTRACE */
130 #endif /* SILCMEMORY_H */