1 // Created on: 2009-12-30
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <NCollection_HeapAllocator.hxx>
17 #include <Standard_OutOfMemory.hxx>
18 #include <Standard_Mutex.hxx>
20 IMPLEMENT_STANDARD_HANDLE (NCollection_HeapAllocator, NCollection_BaseAllocator)
21 IMPLEMENT_STANDARD_RTTIEXT(NCollection_HeapAllocator, NCollection_BaseAllocator)
23 //=======================================================================
26 //=======================================================================
28 void * NCollection_HeapAllocator::Allocate (const Standard_Size theSize)
30 // the size is rounded up to word size.
31 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
32 void* aResult = malloc (aRoundSize);
36 Sprintf (aBuffer, "Failed to allocate %" PRIuPTR " bytes in global dynamic heap", theSize);
37 Standard_OutOfMemory::Raise (aBuffer);
42 //=======================================================================
45 //=======================================================================
47 void NCollection_HeapAllocator::Free (void * anAddress)
49 if (anAddress) free(anAddress);
52 //=======================================================================
53 //function : GlobalHeapAllocator
55 //=======================================================================
57 const Handle_NCollection_HeapAllocator&
58 NCollection_HeapAllocator::GlobalHeapAllocator()
60 static Handle(NCollection_HeapAllocator) pAllocator;
61 if (pAllocator.IsNull()) {
62 static Standard_Mutex theMutex;
63 Standard_Mutex::Sentry aSentry (theMutex);
64 if (pAllocator.IsNull()) {
65 pAllocator = new NCollection_HeapAllocator;