Anope IRC Services  Version 2.0
win32_memory.cpp
Go to the documentation of this file.
1 /* +------------------------------------+
2  * | Inspire Internet Relay Chat Daemon |
3  * +------------------------------------+
4  *
5  * InspIRCd: (C) 2002-2011 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  * the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13 
14 #ifdef _WIN32
15 
16 #include <windows.h>
17 #include <exception>
18 #include <new>
19 #include <new.h>
20 
31 void *::operator new(size_t iSize)
32 {
33  void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* zero memory for unix compatibility */
34  /* This is the correct behaviour according to C++ standards for out of memory,
35  * not returning null -- Brain
36  */
37  if (!ptr)
38  throw std::bad_alloc();
39  else
40  return ptr;
41 }
42 
43 void ::operator delete(void *ptr)
44 {
45  if (ptr)
46  HeapFree(GetProcessHeap(), 0, ptr);
47 }
48 
49 void *operator new[](size_t iSize)
50 {
51  void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* Why were we initializing the memory to zeros here? This is just a waste of cpu! */
52  if (!ptr)
53  throw std::bad_alloc();
54  else
55  return ptr;
56 }
57 
58 void operator delete[](void *ptr)
59 {
60  if (ptr)
61  HeapFree(GetProcessHeap(), 0, ptr);
62 }
63 
64 #endif