0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Standard / Standard_DefineAlloc.hxx
CommitLineData
6aca4d39 1// Created on: 2012-01-19
b311480e 2// Created by: Dmitry BOBYLEV
6aca4d39 3// Copyright (c) 2012-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
1c35b92f 15
16#ifndef _Standard_DefineAlloc_HeaderFile
acc62560 17#define _Standard_DefineAlloc_HeaderFile
1c35b92f 18
19// Macro to override new and delete operators for arrays.
20// Defined to empty for old SUN compiler
21# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
22# define DEFINE_STANDARD_ALLOC_ARRAY
23# else
24# define DEFINE_STANDARD_ALLOC_ARRAY \
25 void* operator new[] (size_t theSize) \
26 { \
27 return Standard::Allocate (theSize); \
28 } \
29 void operator delete[] (void* theAddress) \
30 { \
31 Standard::Free (theAddress); \
32 }
33# endif
34
35// Macro to override placement new and placement delete operators.
36// For Borland C and old SUN compilers do not define placement delete
37// as it is not supported.
38# if defined(__BORLANDC__) || (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530))
39# define DEFINE_STANDARD_ALLOC_PLACEMENT \
40 void* operator new (size_t, void* theAddress) \
41 { \
42 return theAddress; \
43 }
44# else
45# define DEFINE_STANDARD_ALLOC_PLACEMENT \
46 void* operator new (size_t, void* theAddress) \
47 { \
48 return theAddress; \
49 } \
50 void operator delete (void*, void*) \
51 { \
52 }
53# endif
54
55// Macro to override operators new and delete to use OCC memory manager
56# define DEFINE_STANDARD_ALLOC \
57 void* operator new (size_t theSize) \
58 { \
59 return Standard::Allocate (theSize); \
60 } \
61 void operator delete (void* theAddress) \
62 { \
547702a1 63 Standard::Free (theAddress); \
1c35b92f 64 } \
65 DEFINE_STANDARD_ALLOC_ARRAY \
66 DEFINE_STANDARD_ALLOC_PLACEMENT
67
68// Declare operator new in global scope for old sun compiler
69#ifndef WORKAROUND_SUNPRO_NEW_PLACEMENT
70#define WORKAROUND_SUNPRO_NEW_PLACEMENT
71#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x420)
72inline void* operator new(size_t,void* anAddress)
73{
74 return anAddress;
75}
76#endif
77#endif
78
acc62560 79//! @def STANDARD_ALIGNED(theAlignment, theType, theVar)
80//! Declare variable with memory alignment.
81//! @code
82//! static const STANDARD_ALIGNED(8, char, THE_ARRAY)[] = {0xFF, 0xFE, 0xFA, 0xFB, 0xFF, 0x11, 0x22, 0x33};
83//! @endcode
84#if defined(_MSC_VER)
85 #define STANDARD_ALIGNED(theAlignment, theType, theVar) __declspec(align(theAlignment)) theType theVar
86#elif defined(__GNUC__)
87 #define STANDARD_ALIGNED(theAlignment, theType, theVar) theType __attribute__ ((aligned (theAlignment))) theVar
88#else
89 #define STANDARD_ALIGNED(theAlignment, theType, theVar) theType theVar
e2e80ff7 90#endif
acc62560 91
92#endif // _Standard_DefineAlloc_HeaderFile