1 // Created on: 2005-03-15
2 // Created by: Peter KURNEV
3 // Copyright (c) 2005-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_MMgrRaw.hxx>
17 #include <Standard_OutOfMemory.hxx>
20 //=======================================================================
21 //function : Standard_MMgrRaw
23 //=======================================================================
25 Standard_MMgrRaw::Standard_MMgrRaw(const Standard_Boolean aClear)
30 //=======================================================================
33 //=======================================================================
35 Standard_Address Standard_MMgrRaw::Allocate(const Standard_Size aSize)
37 // the size is rounded up to 4 since some OCC classes
38 // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
39 const Standard_Size aRoundSize = (aSize + 3) & ~0x3;
40 // we use ?: operator instead of if() since it is faster :-)
41 Standard_Address aPtr = ( myClear ? calloc(aRoundSize, sizeof(char)) :
44 throw Standard_OutOfMemory("Standard_MMgrRaw::Allocate(): malloc failed");
48 //=======================================================================
51 //=======================================================================
53 void Standard_MMgrRaw::Free(Standard_Address theStorage)
58 //=======================================================================
59 //function : Reallocate
61 //=======================================================================
63 Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address theStorage,
64 const Standard_Size theSize)
66 // the size is rounded up to 4 since some OCC classes
67 // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
68 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
69 Standard_Address newStorage = (Standard_Address)realloc(theStorage, aRoundSize);
71 throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed");
72 // Note that it is not possible to ensure that additional memory
73 // allocated by realloc will be cleared (so as to satisfy myClear mode);
74 // in order to do that we would need using memset...