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