42cf5bc1 |
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 | |
42cf5bc1 |
20 | #include <Standard_DefineAlloc.hxx> |
42cf5bc1 |
21 | #include <Standard_Address.hxx> |
22 | #include <Standard_Size.hxx> |
23 | #include <Standard_Integer.hxx> |
c60ae7f6 |
24 | |
42cf5bc1 |
25 | class Standard_ErrorHandlerCallback; |
26 | class Standard_ErrorHandler; |
27 | class Standard_GUID; |
28 | class Standard_Persistent; |
29 | class Standard_Transient; |
30 | class Standard_Failure; |
31 | |
c60ae7f6 |
32 | //! The package Standard provides global memory allocator and other basic |
33 | //! services used by other OCCT components. |
42cf5bc1 |
34 | |
35 | class Standard |
36 | { |
37 | public: |
38 | |
39 | DEFINE_STANDARD_ALLOC |
40 | |
41 | |
42 | //! Allocates memory blocks |
43 | //! aSize - bytes to allocate |
44 | Standard_EXPORT static Standard_Address Allocate (const Standard_Size aSize); |
45 | |
46 | //! Deallocates memory blocks |
c60ae7f6 |
47 | //! @param thePtr - previously allocated memory block to be freed |
48 | Standard_EXPORT static void Free (const Standard_Address thePtr); |
5b111128 |
49 | |
c60ae7f6 |
50 | //! Template version of function Free(), nullifies the argument pointer |
51 | //! @param thePtr - previously allocated memory block to be freed |
52 | template <typename T> |
53 | static inline void Free (T*& thePtr) |
54 | { |
55 | Free ((void*)thePtr); |
56 | thePtr = 0; |
57 | } |
42cf5bc1 |
58 | |
59 | //! Reallocates memory blocks |
60 | //! aStorage - previously allocated memory block |
61 | //! aNewSize - new size in bytes |
62 | Standard_EXPORT static Standard_Address Reallocate (const Standard_Address aStorage, const Standard_Size aNewSize); |
63 | |
64 | //! Allocates aligned memory blocks. |
65 | //! Should be used with CPU instructions which require specific alignment. |
66 | //! For example: SSE requires 16 bytes, AVX requires 32 bytes. |
67 | //! @param theSize bytes to allocate |
68 | //! @param theAlign alignment in bytes |
69 | Standard_EXPORT static Standard_Address AllocateAligned (const Standard_Size theSize, const Standard_Size theAlign); |
70 | |
71 | //! Deallocates memory blocks |
72 | //! @param thePtrAligned the memory block previously allocated with AllocateAligned() |
73 | Standard_EXPORT static void FreeAligned (const Standard_Address thePtrAligned); |
5b111128 |
74 | |
c60ae7f6 |
75 | //! Template version of function FreeAligned(), nullifies the argument pointer |
76 | //! @param thePtrAligned the memory block previously allocated with AllocateAligned() |
77 | template <typename T> |
78 | static inline void FreeAligned (T*& thePtrAligned) |
79 | { |
80 | FreeAligned ((void* )thePtrAligned); |
81 | thePtrAligned = 0; |
82 | } |
42cf5bc1 |
83 | |
84 | //! Deallocates the storage retained on the free list |
85 | //! and clears the list. |
86 | //! Returns non-zero if some memory has been actually freed. |
87 | Standard_EXPORT static Standard_Integer Purge(); |
88 | |
42cf5bc1 |
89 | }; |
90 | |
d1a67b9d |
91 | // include definition of handle to make it always visible |
92 | // (put at the and of the file due to cyclic dependency between headers) |
93 | #include <Standard_Transient.hxx> |
42cf5bc1 |
94 | |
42cf5bc1 |
95 | #endif // _Standard_HeaderFile |