win32_memory.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2011 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifdef _WIN32
00015 
00016 #include <windows.h>
00017 #include <exception>
00018 #include <new>
00019 #include <new.h>
00020 
00031 void *::operator new(size_t iSize)
00032 {
00033         void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* zero memory for unix compatibility */
00034         /* This is the correct behaviour according to C++ standards for out of memory,
00035          * not returning null -- Brain
00036          */
00037         if (!ptr)
00038                 throw std::bad_alloc();
00039         else
00040                 return ptr;
00041 }
00042 
00043 void ::operator delete(void *ptr)
00044 {
00045         if (ptr)
00046                 HeapFree(GetProcessHeap(), 0, ptr);
00047 }
00048 
00049 void *operator new[](size_t iSize)
00050 {
00051         void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* Why were we initializing the memory to zeros here? This is just a waste of cpu! */
00052         if (!ptr)
00053                 throw std::bad_alloc();
00054         else
00055                 return ptr;
00056 }
00057 
00058 void operator delete[](void *ptr)
00059 {
00060         if (ptr)
00061                 HeapFree(GetProcessHeap(), 0, ptr);
00062 }
00063 
00064 #endif