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 /****f* silcutil/SilcMemoryAPI/silc_malloc
42 * void *silc_malloc(size_t size);
46 * Allocates memory of `size' bytes and returns pointer to the allocated
47 * memory area. Free the memory by calling silc_free.
50 void *silc_malloc(size_t size);
52 /****f* silcutil/SilcMemoryAPI/silc_calloc
56 * void *silc_calloc(size_t items, size_t size);
60 * Allocates memory of for an array of `items' elements of `size' bytes
61 * and returns pointer to the allocated memory area. The memory area is
62 * also zeroed. Free the memory by calling silc_free.
65 void *silc_calloc(size_t items, size_t size);
67 /****f* silcutil/SilcMemoryAPI/silc_realloc
71 * void *silc_realloc(void *ptr, size_t size);
75 * Change the size of the memory block indicated by `ptr' to the new
76 * size of `size' bytes. The contents of `ptr' will not be changed.
77 * If `ptr' is NULL the call is equivalent to silc_malloc. If the
78 * `size' is zero (0) the call is equivalent to silc_free. Free the
79 * memory by calling silc_free.
83 * The pointer returned to the reallocated memory area might not be
87 void *silc_realloc(void *ptr, size_t size);
89 /****f* silcutil/SilcMemoryAPI/silc_free
93 * void silc_free(void *ptr);
97 * Frees the memory area indicated by the `ptr'. If `ptr' is NULL no
98 * operation is performed.
101 void silc_free(void *ptr);
103 /****f* silcutil/SilcMemoryAPI/silc_memdup
107 * void *silc_memdup(const void *ptr, size_t size);
111 * Duplicates the memory area indicated by `ptr' which is of size
112 * of `size' bytes. Returns pointer to the duplicated memory area.
113 * This NULL terminates the dupped memory area by allocating `size' + 1
114 * bytes, so this function can be used to duplicate strings that does
115 * not have NULL termination.
118 void *silc_memdup(const void *ptr, size_t size);
120 #endif /* SILCMEMORY_H */