1 // Created on: 22.07.11
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2002-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_WinHeapAllocator.hxx>
17 #include <Standard_OutOfMemory.hxx>
19 #if(defined(_WIN32) || defined(__WIN32__))
23 IMPLEMENT_STANDARD_HANDLE (NCollection_WinHeapAllocator,
24 NCollection_BaseAllocator)
25 IMPLEMENT_STANDARD_RTTIEXT(NCollection_WinHeapAllocator,
26 NCollection_BaseAllocator)
28 //=======================================================================
29 //function : NCollection_WinHeapAllocator
30 //purpose : Main constructor
31 //=======================================================================
32 NCollection_WinHeapAllocator::NCollection_WinHeapAllocator
33 (const size_t theInitSizeBytes)
34 : NCollection_BaseAllocator(),
35 #if(defined(_WIN32) || defined(__WIN32__))
36 myHeapH (HeapCreate (0, theInitSizeBytes, 0)),
38 myToZeroMemory (Standard_False)
40 #if(defined(_WIN32) || defined(__WIN32__))
41 // activate LHF to improve small size allocations
43 HeapSetInformation (myHeapH, HeapCompatibilityInformation,
44 &aHeapInfo, sizeof(aHeapInfo));
48 //=======================================================================
49 //function : ~NCollection_WinHeapAllocator
50 //purpose : Destructor
51 //=======================================================================
52 NCollection_WinHeapAllocator::~NCollection_WinHeapAllocator()
54 #if(defined(_WIN32) || defined(__WIN32__))
55 HeapDestroy (myHeapH);
60 //=======================================================================
63 //=======================================================================
64 void* NCollection_WinHeapAllocator::Allocate (const Standard_Size theSize)
66 // the size is rounded up to word size.
67 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
68 #if(defined(_WIN32) || defined(__WIN32__))
69 void* aResult = HeapAlloc (myHeapH, myToZeroMemory ? HEAP_ZERO_MEMORY : 0,
72 void* aResult = malloc (aRoundSize);
77 Sprintf (aBuf, "Failed to allocate " PRIuPTR " bytes in local dynamic heap", theSize);
78 Standard_OutOfMemory::Raise (aBuf);
83 //=======================================================================
86 //=======================================================================
87 void NCollection_WinHeapAllocator::Free (void* theAddress)
89 if (theAddress != NULL)
91 #if(defined(_WIN32) || defined(__WIN32__))
92 HeapFree (myHeapH, 0, theAddress);