1 // Created on: 2010-03-15
2 // Created by: Sergey KUUL
3 // Copyright (c) 2010-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 <Standard_MMgrTBBalloc.hxx>
17 #include <Standard_OutOfMemory.hxx>
19 // paralleling with Intel TBB
21 #include <tbb/scalable_allocator.h>
24 #define scalable_malloc malloc
25 #define scalable_calloc calloc
26 #define scalable_realloc realloc
27 #define scalable_free free
30 //=======================================================================
31 //function : Standard_MMgrTBBalloc
33 //=======================================================================
35 Standard_MMgrTBBalloc::Standard_MMgrTBBalloc(const Standard_Boolean aClear)
40 //=======================================================================
43 //=======================================================================
45 Standard_Address Standard_MMgrTBBalloc::Allocate(const Standard_Size aSize)
47 // the size is rounded up to 4 since some OCC classes
48 // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
49 const Standard_Size aRoundSize = (aSize + 3) & ~0x3;
50 // we use ?: operator instead of if() since it is faster :-)
51 Standard_Address aPtr = ( myClear ? scalable_calloc(aRoundSize, sizeof(char)) :
52 scalable_malloc(aRoundSize) );
54 throw Standard_OutOfMemory("Standard_MMgrTBBalloc::Allocate(): malloc failed");
58 //=======================================================================
61 //=======================================================================
63 void Standard_MMgrTBBalloc::Free (Standard_Address theStorage)
65 scalable_free (theStorage);
68 //=======================================================================
69 //function : Reallocate
71 //=======================================================================
73 Standard_Address Standard_MMgrTBBalloc::Reallocate (Standard_Address theStorage,
74 const Standard_Size theSize)
76 // the size is rounded up to 4 since some OCC classes
77 // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
78 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
79 Standard_Address newStorage = (Standard_Address)scalable_realloc(theStorage, aRoundSize);
81 throw Standard_OutOfMemory("Standard_MMgrTBBalloc::Reallocate(): realloc failed");
82 // Note that it is not possible to ensure that additional memory
83 // allocated by realloc will be cleared (so as to satisfy myClear mode);
84 // in order to do that we would need using memset...