VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp@ 3460

Last change on this file since 3460 was 2981, checked in by vboxsync, 18 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1/* $Id: alloc-ef-cpp.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Memory Allocation, C++ electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include "alloc-ef.h"
26
27#ifdef RTALLOC_EFENCE_CPP /* rest of the file */
28
29#include <new>
30
31
32/*******************************************************************************
33* Defined Constants And Macros *
34*******************************************************************************/
35/** @todo test this on MSC */
36
37/* MSC declares the operators as cdecl it seems. */
38#ifdef _MSC_VER
39# define RT_EF_CDECL __cdecl
40#else
41# define RT_EF_CDECL
42#endif
43
44/* MSC doesn't use the standard namespace. */
45#ifdef _MSC_VER
46# define RT_EF_SIZE_T size_t
47#else
48# define RT_EF_SIZE_T std::size_t
49#endif
50
51
52void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
53{
54 void *pv = rtMemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
55 if (!pv)
56 throw std::bad_alloc();
57 return pv;
58}
59
60
61void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
62{
63 void *pv = rtMemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
64 return pv;
65}
66
67
68void RT_EF_CDECL operator delete(void *pv) throw()
69{
70 rtMemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
71}
72
73
74void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
75{
76 rtMemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
77}
78
79
80/*
81 *
82 * Array object form.
83 * Array object form.
84 * Array object form.
85 *
86 */
87
88void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
89{
90 void *pv = rtMemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
91 if (!pv)
92 throw std::bad_alloc();
93 return pv;
94}
95
96
97void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
98{
99 void *pv = rtMemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
100 return pv;
101}
102
103
104void RT_EF_CDECL operator delete[](void * pv) throw()
105{
106 rtMemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
107}
108
109
110void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
111{
112 rtMemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
113}
114
115#endif /* RTALLOC_EFENCE_CPP */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette