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>
21 //=======================================================================
24 //=======================================================================
26 void * NCollection_HeapAllocator::Allocate (const Standard_Size theSize)
28 // the size is rounded up to word size.
29 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
30 void* aResult = malloc (aRoundSize);
34 Sprintf (aBuffer, "Failed to allocate %" PRIuPTR " bytes in global dynamic heap", theSize);
35 Standard_OutOfMemory::Raise (aBuffer);
40 //=======================================================================
43 //=======================================================================
45 void NCollection_HeapAllocator::Free (void * anAddress)
47 if (anAddress) free(anAddress);
50 //=======================================================================
51 //function : GlobalHeapAllocator
53 //=======================================================================
55 const Handle(NCollection_HeapAllocator)&
56 NCollection_HeapAllocator::GlobalHeapAllocator()
58 static Handle(NCollection_HeapAllocator) pAllocator;
59 if (pAllocator.IsNull()) {
60 static Standard_Mutex theMutex;
61 Standard_Mutex::Sentry aSentry (theMutex);
62 if (pAllocator.IsNull()) {
63 pAllocator = new NCollection_HeapAllocator;