VirtualBox

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

Last change on this file since 28271 was 28271, checked in by vboxsync, 15 years ago

IPRT: Some efence adjustments, adding RTMemAllocVar and RTMemAllocZVar for dealing with struct + string style allocations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/* $Id: alloc-ef-cpp.cpp 28271 2010-04-13 19:29:42Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, C++ electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include "alloc-ef.h"
35
36
37#if defined(RTALLOC_EFENCE_CPP) || defined(RTMEM_WRAP_TO_EF_APIS) /* rest of the file */
38
39#include <new>
40
41
42/*******************************************************************************
43* Defined Constants And Macros *
44*******************************************************************************/
45/** @todo test this on MSC */
46
47/* MSC declares the operators as cdecl it seems. */
48#ifdef _MSC_VER
49# define RT_EF_CDECL __cdecl
50#else
51# define RT_EF_CDECL
52#endif
53
54/* MSC doesn't use the standard namespace. */
55#ifdef _MSC_VER
56# define RT_EF_SIZE_T size_t
57#else
58# define RT_EF_SIZE_T std::size_t
59#endif
60
61
62void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
63{
64 void *pv = rtMemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
65 if (!pv)
66 throw std::bad_alloc();
67 return pv;
68}
69
70
71void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
72{
73 void *pv = rtMemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
74 return pv;
75}
76
77
78void RT_EF_CDECL operator delete(void *pv) throw()
79{
80 rtMemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
81}
82
83
84void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
85{
86 rtMemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
87}
88
89
90/*
91 *
92 * Array object form.
93 * Array object form.
94 * Array object form.
95 *
96 */
97
98void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
99{
100 void *pv = rtMemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
101 if (!pv)
102 throw std::bad_alloc();
103 return pv;
104}
105
106
107void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
108{
109 void *pv = rtMemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
110 return pv;
111}
112
113
114void RT_EF_CDECL operator delete[](void * pv) throw()
115{
116 rtMemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
117}
118
119
120void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
121{
122 rtMemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
123}
124
125#endif /* RTALLOC_EFENCE_CPP || RTMEM_WRAP_TO_EF_APIS */
Note: See TracBrowser for help on using the repository browser.

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