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