2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /** On windows, all dll files and executables have their own private heap,
26 * whereas on POSIX systems, shared objects loaded into an executable share
27 * the executable's heap. This means that if we pass an arbitrary pointer to
28 * a windows DLL which is not allocated in that dll, without some form of
29 * marshalling, we get a page fault. To fix this, these overrided operators
30 * new and delete use the windows HeapAlloc and HeapFree functions to claim
31 * memory from the windows global heap. This makes windows 'act like' POSIX
32 * when it comes to memory usage between dlls and exes.
35 void * ::operator new(size_t iSize)
37 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
38 /* This is the correct behaviour according to C++ standards for out of memory,
39 * not returning null -- Brain
42 throw std::bad_alloc();
47 void ::operator delete(void * ptr)
50 HeapFree(GetProcessHeap(), 0, ptr);
53 void * operator new[] (size_t iSize)
55 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
57 throw std::bad_alloc();
62 void operator delete[] (void* ptr)
65 HeapFree(GetProcessHeap(), 0, ptr);