#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;
}
#include <Standard_OutOfRange.hxx>
#include <Standard_Failure.hxx>
+// macro to get size of C array
+#define CARRAY_LENGTH(arr) (sizeof(arr)/sizeof(arr[0]))
+
math_SingleTab::math_SingleTab(const Standard_Integer LowerIndex,
const Standard_Integer UpperIndex) :
-
- isAllocated(Standard_True),
+ Addr(Buf),
+ isAllocated(UpperIndex - LowerIndex + 1 > CARRAY_LENGTH(Buf)),
First(LowerIndex), Last(UpperIndex)
{
- Item* TheAddr = (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
+ Item* TheAddr = !isAllocated? Buf :
+ (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
Addr = (Standard_Address) (TheAddr - First);
-//cout << " Vector allocation = " << Addr << endl;
}
math_SingleTab::math_SingleTab(const Item& Tab,
First(LowerIndex), Last(UpperIndex)
{
-//cout << " Vector allocation = " << Addr << endl;
}
void math_SingleTab::Init(const Item& InitValue)
math_SingleTab::math_SingleTab(const math_SingleTab& Other) :
- isAllocated(Standard_True),
+ isAllocated(Other.Last - Other.First + 1 > CARRAY_LENGTH(Buf)),
First(Other.First),
Last(Other.Last)
{
- Item* TheAddr = (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
+ Item* TheAddr = !isAllocated? Buf :
+ (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
Addr = (Standard_Address) (TheAddr - First);
-//cout << " Vector allocation = " << Addr << endl;
Item* TheOtherAddr = (Item*) Other.Addr;
memmove((void*) TheAddr, (const void*) (TheOtherAddr + First),
(size_t)(Last - First + 1) * sizeof(Item));
void math_SingleTab::Free()
{
-//cout << " Vector deallocation = " << Addr << endl;
if(isAllocated) {
Standard_Address it = (Standard_Address)&((Item*)Addr)[First];
Standard::Free(it);