KVIrc  4.9.2
DeveloperAPIs
KviMemory.h
Go to the documentation of this file.
1 #ifndef _KVI_MALLOC_H_
2 #define _KVI_MALLOC_H_
3 
4 //=============================================================================
5 //
6 // File : KviMemory.h
7 // Creation date : Sun Jun 18 2000 18:18:36 CEST by Szymon Stefanek
8 //
9 // This file is part of the KVIrc IRC client distribution
10 // Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net)
11 //
12 // This program is FREE software. You can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the HOPE that it will be USEFUL,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 // See the GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, write to the Free Software Foundation,
24 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 //=============================================================================
29 // C memory allocation routines: macros in common compilations
30 //=============================================================================
31 
32 #include "kvi_settings.h"
33 
34 #include <stdlib.h>
35 #include <string.h>
36 
48 namespace KviMemory
49 {
50 
51 #ifdef COMPILE_MEMORY_PROFILE
52 
53 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
54 #error "This stuff should be never compiled on Windows"
55 #endif
56 
63  KVILIB_API void * allocate(int size);
64 
72  KVILIB_API void * reallocate(void * ptr, int size);
73 
80  KVILIB_API void free(void * ptr);
81 
82 #else
83 
84 #ifdef COMPILE_MEMORY_CHECKS
85 
86 #ifdef COMPILE_ON_WINDOWS
87 #error "This stuff should be never compiled on Windows"
88 #endif
89 
93  KVILIB_API void outOfMemory();
94 
95  inline void * allocate(int size)
96  {
97  void * ptr = ::malloc(size);
98  if(!ptr)
99  outOfMemory();
100  return ptr;
101  }
102 
103  inline void * reallocate(void * ptr, int size)
104  {
105  ptr = ::realloc(ptr, size);
106  if(!ptr)
107  outOfMemory();
108  return ptr;
109  }
110 
111 #else
112 
113  inline void * allocate(int size)
114  {
115  return ::malloc(size);
116  }
117 
118  inline void * reallocate(void * ptr, int size)
119  {
120  return ::realloc(ptr, size);
121  }
122 
123 #endif
124 
125  inline void free(void * ptr)
126  {
127  ::free(ptr);
128  }
129 #endif
130 
131 
139  inline void move(void * dst_ptr, const void * src_ptr, int len)
140  {
141  memmove(dst_ptr, src_ptr, len);
142  }
143 
152  inline void set(void * dst_ptr, char c, int len)
153  {
154  memset(dst_ptr, c, len);
155  }
156 
166  inline void copy(void * dst_ptr, const void * src_ptr, int len)
167  {
168  memcpy(dst_ptr, src_ptr, len);
169  }
170 
171 } // namespace KviMemory
172 
173 #endif //_KVI_MALLOC_H_
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
void * reallocate(void *ptr, int size)
Definition: KviMemory.h:118
void * allocate(int size)
COMPILE_MEMORY_PROFILE.
Definition: KviMemory.h:113
void set(void *dst_ptr, char c, int len)
Initializes len bytes of memory starting from dst_ptr to c.
Definition: KviMemory.h:152
This file contains compile time settings.
void copy(void *dst_ptr, const void *src_ptr, int len)
Moves len bytes from src_ptr to dst_ptr.
Definition: KviMemory.h:166
void free(void *ptr)
COMPILE_MEMORY_CHECKS.
Definition: KviMemory.h:125
void move(void *dst_ptr, const void *src_ptr, int len)
COMPILE_MEMORY_PROFILE.
Definition: KviMemory.h:139
#define KVILIB_API
Definition: kvi_settings.h:125