usermode/library/malloc-original/src/uselibhoard.cpp

00001 
00002 //
00003 // The Hoard Multiprocessor Memory Allocator
00004 // www.hoard.org
00005 //
00006 // Author: Emery Berger, http://www.cs.utexas.edu/users/emery
00007 //
00008 // Copyright (c) 1998-2001, The University of Texas at Austin.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Library General Public License as
00012 // published by the Free Software Foundation, http://www.fsf.org.
00013 //
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Library General Public License for more details.
00018 //
00020 
00021 // This object module comment is a command to the linker 
00022 //      to force a reference to ReferenceLibHoard below
00023 //#pragma comment(linker, "/include:_ReferenceLibHoard")
00024 
00025 #define WIN32_LEAN_AND_MEAN
00026 #include <windows.h>
00027 
00028 
00029 extern "C" {
00030 
00031 __declspec(dllimport) int ReferenceMe;
00032 
00033 }
00034 
00035 // Force a reference to libhoard that loads the DLL very early,
00036 // before even main() is executed.
00037  
00038 namespace LibHoardInternal {
00039         class ReferToLibHoard {
00040            public:
00041                    ReferToLibHoard (void) {
00042                                 (void)LoadLibraryA("libhoard.dll");
00043                                 ReferenceMe = 1; 
00044                    }
00045            };
00046 
00047    volatile static ReferToLibHoard oneRef;
00048 };
00049 
00050 namespace std {
00051         struct nothrow_t;
00052 };
00053 
00054 
00055 // Reroute all C++ calls in this executable to use malloc & free.
00056 
00057 extern "C" void * malloc (size_t);
00058 extern "C" void free (void *);
00059 
00060 void * operator new (size_t size)
00061 {
00062   return malloc (size);
00063 }
00064 
00065 void * operator new (size_t size, const std::nothrow_t&) throw() {
00066   return malloc (size);
00067 } 
00068 
00069 void * operator new[] (size_t size)
00070 {
00071   return malloc (size);
00072 }
00073 
00074 void * operator new[] (size_t size, const std::nothrow_t&) throw() {
00075   return malloc (size);
00076 } 
00077 
00078 void operator delete (void * ptr)
00079 {
00080   free (ptr);
00081 }
00082 
00083 void operator delete[] (void * ptr)
00084 {
00085   free (ptr);
00086 }
00087 

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7