1 /**
2  * @file memory.h
3  * Memory allocations.
4  *
5  * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
6  * @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
7  *
8  * @par License
9  * GPL: http://www.gnu.org/licenses/gpl.html
10  *
11  * <small>This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2 of the License, or (at your
14  * option) any later version. This program is distributed in the hope that it
15  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details. You should have received a copy of the GNU
18  * General Public License along with this program; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA</small>
21  */
22 
23 #ifndef LIBDENG_SYSTEM_MEMORY_H
24 #define LIBDENG_SYSTEM_MEMORY_H
25 
26 #include <de/liblegacy.h>
27 #include <string.h> // memcpy
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /// @addtogroup legacy
34 /// @{
35 
36 DENG_PUBLIC void *M_Malloc(size_t size);
37 
38 DENG_PUBLIC void *M_Calloc(size_t size);
39 
40 /**
41  * Changes the size of a previously allocated memory block, allocates new
42  * memory, or frees previously allocated memory.
43  *
44  * - If @a ptr is NULL and @a size is zero, nothing happens and NULL is returned.
45  * - If @a ptr is NULL and @a size is not zero, new memory is allocated
46  *   and a pointer to it is returned.
47  * - If @a ptr is not NULL and @a size is not zero, the memory pointed to
48  *   by @a ptr is resized, and the allocated memory's (possible) new address
49  *   is returned.
50  * - If @a ptr is not NULL and @a size is zero, the memory pointed to by
51  *   @a ptr is freed (using M_Free()) and NULL is returned.
52  *
53  * @param ptr   Previously allocated memory, or NULL.
54  * @param size  New size for the allocated memory.
55  *
56  * @return Allocated memory, or NULL.
57  */
58 DENG_PUBLIC void *M_Realloc(void *ptr, size_t size);
59 
60 DENG_PUBLIC void *M_MemDup(void const *ptr, size_t size);
61 
62 DENG_PUBLIC void M_Free(void *ptr);
63 
64 DENG_PUBLIC char *M_StrDup(char const *str);
65 
66 /// @}
67 
68 #ifdef __cplusplus
69 } // extern "C"
70 #endif
71 
72 #endif // LIBDENG_SYSTEM_MEMORY_H
73