0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / Standard / Standard_MMgrRaw.cxx
CommitLineData
b311480e 1// Created on: 2005-03-15
2// Created by: Peter KURNEV
973c2be1 3// Copyright (c) 2005-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <Standard_MMgrRaw.hxx>
17#include <Standard_OutOfMemory.hxx>
18#include <stdlib.h>
19
20//=======================================================================
21//function : Standard_MMgrRaw
22//purpose :
23//=======================================================================
24
25Standard_MMgrRaw::Standard_MMgrRaw(const Standard_Boolean aClear)
26{
27 myClear = aClear;
28}
29
30//=======================================================================
31//function : Allocate
32//purpose :
33//=======================================================================
34
35Standard_Address Standard_MMgrRaw::Allocate(const Standard_Size aSize)
36{
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)) :
42 malloc(aRoundSize) );
43 if ( ! aPtr )
9775fa61 44 throw Standard_OutOfMemory("Standard_MMgrRaw::Allocate(): malloc failed");
7fd59977 45 return aPtr;
46}
47
48//=======================================================================
49//function : Free
50//purpose :
51//=======================================================================
52
547702a1 53void Standard_MMgrRaw::Free(Standard_Address theStorage)
7fd59977 54{
547702a1 55 free(theStorage);
7fd59977 56}
57
58//=======================================================================
59//function : Reallocate
60//purpose :
61//=======================================================================
62
547702a1 63Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address theStorage,
64 const Standard_Size theSize)
7fd59977 65{
66 // the size is rounded up to 4 since some OCC classes
67 // (e.g. TCollection_AsciiString) assume memory to be double word-aligned
547702a1 68 const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
69 Standard_Address newStorage = (Standard_Address)realloc(theStorage, aRoundSize);
7fd59977 70 if ( ! newStorage )
9775fa61 71 throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed");
7fd59977 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...
7fd59977 75 return newStorage;
76}