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 IMPLEMENT_STANDARD_RTTIEXT(NCollection_WinHeapAllocator,NCollection_BaseAllocator)
21 #if(defined(_WIN32) || defined(__WIN32__))
25 //=======================================================================
26 //function : NCollection_WinHeapAllocator
27 //purpose : Main constructor
28 //=======================================================================
29 NCollection_WinHeapAllocator::NCollection_WinHeapAllocator
30 (const size_t theInitSizeBytes)
31 : NCollection_BaseAllocator(),
32 #if(defined(_WIN32) || defined(__WIN32__))
33 myHeapH (HeapCreate (0, theInitSizeBytes, 0)),
35 myToZeroMemory (Standard_False)
37 #if defined(_WIN32) && (_WIN32_WINNT >= 0x0501)
38 // activate LHF to improve small size allocations
40 HeapSetInformation (myHeapH, HeapCompatibilityInformation,
41 &aHeapInfo, sizeof(aHeapInfo));
43 (void )theInitSizeBytes;
47 //=======================================================================
48 //function : ~NCollection_WinHeapAllocator
49 //purpose : Destructor
50 //=======================================================================
51 NCollection_WinHeapAllocator::~NCollection_WinHeapAllocator()
53 #if(defined(_WIN32) || defined(__WIN32__))
54 HeapDestroy (myHeapH);
59 //=======================================================================
62 //=======================================================================
63 void* NCollection_WinHeapAllocator::Allocate (const Standard_Size theSize)
65 // the size is rounded up to word size.
66 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
67 #if(defined(_WIN32) || defined(__WIN32__))
68 void* aResult = HeapAlloc (myHeapH, myToZeroMemory ? HEAP_ZERO_MEMORY : 0,
71 void* aResult = malloc (aRoundSize);
76 Sprintf (aBuf, "Failed to allocate %" PRIuPTR " bytes in local dynamic heap", theSize);
77 throw Standard_OutOfMemory(aBuf);
82 //=======================================================================
85 //=======================================================================
86 void NCollection_WinHeapAllocator::Free (void* theAddress)
88 if (theAddress != NULL)
90 #if(defined(_WIN32) || defined(__WIN32__))
91 HeapFree (myHeapH, 0, theAddress);