Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 08:43:33

0001 // Created on: 1991-09-05
0002 // Created by: J.P. TIRAUlt
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Standard_HeaderFile
0018 #define _Standard_HeaderFile
0019 
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <Standard_Integer.hxx>
0022 
0023 //! The package Standard provides global memory allocator and other basic
0024 //! services used by other OCCT components.
0025 
0026 class Standard 
0027 {
0028 public:
0029 
0030   DEFINE_STANDARD_ALLOC
0031 
0032   //! Enumiration of possible allocator types
0033   enum class AllocatorType
0034   {
0035     NATIVE = 0,
0036     OPT = 1,
0037     TBB = 2,
0038     JEMALLOC = 3
0039   };
0040 
0041   //! Returns default allocator type
0042   Standard_EXPORT static AllocatorType GetAllocatorType();
0043   
0044   //! Allocates memory blocks
0045   //! theSize - bytes to  allocate
0046   Standard_EXPORT static Standard_Address Allocate (const Standard_Size theSize);
0047 
0048   //! Allocates memory blocks
0049   //! theSize - bytes to  allocate
0050   Standard_EXPORT static Standard_Address AllocateOptimal (const Standard_Size theSize);
0051   
0052   //! Deallocates memory blocks
0053   //! @param thePtr - previously allocated memory block to be freed
0054   Standard_EXPORT static void Free (const Standard_Address thePtr);
0055   
0056   //! Template version of function Free(), nullifies the argument pointer
0057   //! @param thePtr - previously allocated memory block to be freed
0058   template <typename T>
0059   static inline void Free (T*& thePtr) 
0060   { 
0061     Free ((void*)thePtr);
0062     thePtr = 0;
0063   }
0064   
0065   //! Reallocates memory blocks
0066   //! theStorage - previously allocated memory block
0067   //! theNewSize - new size in bytes
0068   Standard_EXPORT static Standard_Address Reallocate (const Standard_Address theStorage, const Standard_Size theNewSize);
0069   
0070   //! Allocates aligned memory blocks.
0071   //! Should be used with CPU instructions which require specific alignment.
0072   //! For example: SSE requires 16 bytes, AVX requires 32 bytes.
0073   //! @param theSize  bytes to allocate
0074   //! @param theAlign alignment in bytes
0075   Standard_EXPORT static Standard_Address AllocateAligned (const Standard_Size theSize, const Standard_Size theAlign);
0076   
0077   //! Deallocates memory blocks
0078   //! @param thePtrAligned the memory block previously allocated with AllocateAligned()
0079   Standard_EXPORT static void FreeAligned (const Standard_Address thePtrAligned);
0080   
0081   //! Template version of function FreeAligned(), nullifies the argument pointer
0082   //! @param thePtrAligned the memory block previously allocated with AllocateAligned()
0083   template <typename T>
0084   static inline void FreeAligned (T*& thePtrAligned)
0085   {
0086     FreeAligned ((void* )thePtrAligned);
0087     thePtrAligned = 0;
0088   }
0089   
0090   //! Deallocates the storage retained on the free list
0091   //! and clears the list.
0092   //! Returns non-zero if some memory has been actually freed.
0093   Standard_EXPORT static Standard_Integer Purge();
0094 
0095   //! Appends backtrace to a message buffer.
0096   //! Stack information might be incomplete in case of stripped binaries.
0097   //! Implementation details:
0098   //! - Not implemented for Android, iOS, QNX and UWP platforms.
0099   //! - On non-Windows platform, this function is a wrapper to backtrace() system call.
0100   //! - On Windows (Win32) platform, the function loads DbgHelp.dll dynamically,
0101   //!   and no stack will be provided if this or companion libraries (SymSrv.dll, SrcSrv.dll, etc.) will not be found;
0102   //!   .pdb symbols should be provided on Windows platform to retrieve a meaningful stack;
0103   //!   only x86_64 CPU architecture is currently implemented.
0104   //! @param theBuffer [in] [out] message buffer to extend
0105   //! @param theBufferSize [in] message buffer size
0106   //! @param theNbTraces [in] maximum number of stack traces
0107   //! @param theContext [in] optional platform-dependent frame context;
0108   //!                        in case of DbgHelp (Windows) should be a pointer to CONTEXT
0109   //! @param theNbTopSkip [in] number of traces on top of the stack to skip
0110   //! @return TRUE on success
0111   Standard_EXPORT static Standard_Boolean StackTrace (char* theBuffer,
0112                                                       const int theBufferSize,
0113                                                       const int theNbTraces,
0114                                                       void* theContext = NULL,
0115                                                       const int theNbTopSkip = 0);
0116 
0117 };
0118 
0119 #endif // _Standard_HeaderFile