1+ /**
2+ * =============================================================================
3+ * Source Python
4+ * Copyright (C) 2015 Source Python Development Team. All rights reserved.
5+ * =============================================================================
6+ *
7+ * This program is free software; you can redistribute it and/or modify it under
8+ * the terms of the GNU General Public License, version 3.0, as published by the
9+ * Free Software Foundation.
10+ *
11+ * This program is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+ * details.
15+ *
16+ * You should have received a copy of the GNU General Public License along with
17+ * this program. If not, see <http://www.gnu.org/licenses/>.
18+ *
19+ * As a special exception, the Source Python Team gives you permission
20+ * to link the code of this program (as well as its derivative works) to
21+ * "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+ * by the Valve Corporation. You must obey the GNU General Public License in
23+ * all respects for all other code used. Additionally, the Source.Python
24+ * Development Team grants this exception to all derivative works.
25+ */
26+
27+ #ifndef _MEMORY_ALLOC_H
28+ #define _MEMORY_ALLOC_H
29+
30+ // ============================================================================
31+ // >> INCLUDES
32+ // ============================================================================
33+ #include <malloc.h>
34+ #include "memalloc.h"
35+
36+
37+ // ============================================================================
38+ // >> UTIL_GetMemSize
39+ // ============================================================================
40+ inline size_t UTIL_GetMemSize (void * ptr )
41+ {
42+ #ifdef _WIN32
43+ return g_pMemAlloc -> GetSize (ptr );
44+ #elif defined(__linux__ )
45+ return malloc_usable_size (ptr );
46+ #else
47+ #error "Unsupported platform."
48+ #endif
49+ }
50+
51+
52+ // ============================================================================
53+ // >> UTIL_Alloc
54+ // ============================================================================
55+ inline void * UTIL_Alloc (size_t size )
56+ {
57+ void * pPtr = NULL ;
58+ #ifdef _WIN32
59+ pPtr = g_pMemAlloc -> IndirectAlloc (size );
60+ #elif defined(__linux__ )
61+ pPtr = malloc (size );
62+ #else
63+ #error "Unsupported platform."
64+ #endif
65+ memset (pPtr , 0 , size );
66+ return pPtr ;
67+ }
68+
69+
70+ // ============================================================================
71+ // >> UTIL_Realloc
72+ // ============================================================================
73+ inline void * UTIL_Realloc (void * ptr , size_t size )
74+ {
75+ void * pPtr = NULL ;
76+ #ifdef _WIN32
77+ pPtr = g_pMemAlloc -> Realloc (ptr , size );
78+ #elif defined(__linux__ )
79+ pPtr = realloc (ptr , size );
80+ #else
81+ #error "Unsupported platform."
82+ #endif
83+ return pPtr ;
84+ }
85+
86+
87+ // ============================================================================
88+ // >> UTIL_Dealloc
89+ // ============================================================================
90+ inline void UTIL_Dealloc (void * ptr )
91+ {
92+ #ifdef _WIN32
93+ g_pMemAlloc -> Free (ptr );
94+ #elif defined(__linux__ )
95+ free (ptr );
96+ #else
97+ #error "Unsupported platform."
98+ #endif
99+ }
100+
101+ #endif // _MEMORY_ALLOC_H
0 commit comments