1 /* +------------------------------------+
\r
2 * | Inspire Internet Relay Chat Daemon |
\r
3 * +------------------------------------+
\r
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
\r
6 * See: http://www.inspircd.org/wiki/index.php/Credits
\r
8 * This program is free but copyrighted software; see
\r
9 * the file COPYING for details.
\r
11 * ---------------------------------------------------
\r
14 #include "inspircd_win32wrapper.h"
\r
15 #include <exception>
\r
19 /** On windows, all dll files and executables have their own private heap,
\r
20 * whereas on POSIX systems, shared objects loaded into an executable share
\r
21 * the executable's heap. This means that if we pass an arbitrary pointer to
\r
22 * a windows DLL which is not allocated in that dll, without some form of
\r
23 * marshalling, we get a page fault. To fix this, these overrided operators
\r
24 * new and delete use the windows HeapAlloc and HeapFree functions to claim
\r
25 * memory from the windows global heap. This makes windows 'act like' POSIX
\r
26 * when it comes to memory usage between dlls and exes.
\r
29 void * ::operator new(size_t iSize)
\r
31 void* ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iSize); /* zero memory for unix compatibility */
\r
32 /* This is the correct behaviour according to C++ standards for out of memory,
\r
33 * not returning null -- Brain
\r
36 throw std::bad_alloc();
\r
41 void ::operator delete(void * ptr)
\r
43 HeapFree(GetProcessHeap(), 0, ptr);
\r