1 #include "inspircd_win32wrapper.h"
\r
6 /** On windows, all dll files and executables have their own private heap,
\r
7 * whereas on POSIX systems, shared objects loaded into an executable share
\r
8 * the executable's heap. This means that if we pass an arbitrary pointer to
\r
9 * a windows DLL which is not allocated in that dll, without some form of
\r
10 * marshalling, we get a page fault. To fix this, these overrided operators
\r
11 * new and delete use the windows HeapAlloc and HeapFree functions to claim
\r
12 * memory from the windows global heap. This makes windows 'act like' POSIX
\r
13 * when it comes to memory usage between dlls and exes.
\r
16 void * ::operator new(size_t iSize)
\r
18 void* ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iSize); /* zero memory for unix compatibility */
\r
19 /* This is the correct behaviour according to C++ standards for out of memory,
\r
20 * not returning null -- Brain
\r
23 throw std::bad_alloc();
\r
28 void ::operator delete(void * ptr)
\r
30 HeapFree(GetProcessHeap(), 0, ptr);
\r