bb5364d0a2c674480df11cdce7f5abac5f08d94a
[occt.git] / src / Standard / Standard.hxx
1 // Created on: 1991-09-05
2 // Created by: J.P. TIRAUlt
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Standard_HeaderFile
18 #define _Standard_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Address.hxx>
25 #include <Standard_Size.hxx>
26 #include <Standard_Integer.hxx>
27 class Standard_ErrorHandlerCallback;
28 class Standard_ErrorHandler;
29 class Standard_GUID;
30 class Standard_Persistent;
31 class Standard_Transient;
32 class Standard_Failure;
33
34
35
36 class Standard 
37 {
38 public:
39
40   DEFINE_STANDARD_ALLOC
41
42   
43   //! Allocates memory blocks
44   //! aSize - bytes to  allocate
45   Standard_EXPORT static Standard_Address Allocate (const Standard_Size aSize);
46   
47   //! Deallocates memory blocks
48   //! aStorage - previously allocated memory block to be freed
49   Standard_EXPORT static void Free (const Standard_Address aStorage);
50 template <typename T> static inline void Free (T*& thePtr) { Free ((void*)thePtr); thePtr = 0; }
51   
52   //! Reallocates memory blocks
53   //! aStorage - previously allocated memory block
54   //! aNewSize - new size in bytes
55   Standard_EXPORT static Standard_Address Reallocate (const Standard_Address aStorage, const Standard_Size aNewSize);
56   
57   //! Allocates aligned memory blocks.
58   //! Should be used with CPU instructions which require specific alignment.
59   //! For example: SSE requires 16 bytes, AVX requires 32 bytes.
60   //! @param theSize  bytes to allocate
61   //! @param theAlign alignment in bytes
62   Standard_EXPORT static Standard_Address AllocateAligned (const Standard_Size theSize, const Standard_Size theAlign);
63   
64   //! Deallocates memory blocks
65   //! @param thePtrAligned the memory block previously allocated with AllocateAligned()
66   Standard_EXPORT static void FreeAligned (const Standard_Address thePtrAligned);
67 template <typename T> static inline void FreeAligned (T*& thePtrAligned) { FreeAligned ((void* )thePtrAligned); thePtrAligned = 0; }
68   
69   //! Deallocates the storage retained on the free list
70   //! and clears the list.
71   //! Returns non-zero if some memory has been actually freed.
72   Standard_EXPORT static Standard_Integer Purge();
73
74
75
76
77 protected:
78
79
80
81
82
83 private:
84
85
86
87
88 friend class Standard_ErrorHandlerCallback;
89 friend class Standard_ErrorHandler;
90 friend class Standard_GUID;
91 friend class Standard_Persistent;
92 friend class Standard_Transient;
93 friend class Standard_Failure;
94
95 };
96
97
98
99
100
101
102
103 #endif // _Standard_HeaderFile