-// File math_DoubleTab.gxx
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
// Lpa, le 7/02/92
#include <Standard_Failure.hxx>
#include <Standard_Integer.hxx>
+// macro to get size of C array
+#define CARRAY_LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
+
void math_DoubleTab::Allocate()
{
Standard_Integer RowNumber = UppR - LowR + 1;
Standard_Integer ColNumber = UppC - LowC + 1;
- Item** TheAddr = (Item**) Standard::Allocate(RowNumber * sizeof(Item*));
+ Item** TheAddr = !isAddrAllocated? (Item**)&AddrBuf :
+ (Item**) Standard::Allocate(RowNumber * sizeof(Item*));
Item* Address;
if(isAllocated)
Address = (Item*) Standard::Allocate(RowNumber * ColNumber * sizeof(Item));
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol) :
- isAllocated(Standard_True),
+ Addr(Buf),
+ isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
+ isAllocated((UpperRow - LowerRow + 1) * (UpperCol - LowerCol + 1) > CARRAY_LENGTH(Buf)),
LowR(LowerRow),
UppR(UpperRow),
LowC(LowerCol),
const Standard_Integer LowerCol,
const Standard_Integer UpperCol) :
Addr((void *) &Tab),
+ isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
isAllocated(Standard_False),
LowR(LowerRow),
UppR(UpperRow),
math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
- isAllocated(Standard_True),
+ Addr(Buf),
+ isAddrAllocated(Other.UppR - Other.LowR + 1 > CARRAY_LENGTH(AddrBuf)),
+ isAllocated((Other.UppR - Other.LowR + 1) *
+ (Other.UppC - Other.LowC + 1) > CARRAY_LENGTH(Buf)),
LowR(Other.LowR),
UppR(Other.UppR),
LowC(Other.LowC),
Standard::Free(it);
}
// free the pointers
- Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
- Standard::Free (it);
+ if(isAddrAllocated) {
+ Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
+ Standard::Free (it);
+ }
Addr = 0;
}