1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21 *************************************************************************/
23 #include <ode/odeconfig.h>
25 #include <ode/memory.h>
26 #include <ode/error.h>
30 static inline int roundUpToPowerOfTwo (int x
)
33 while (i
< x
) i
<<= 1;
38 void dArrayBase::_freeAll (int sizeofT
)
41 if (_data
== this+1) return; // if constructLocalArray() was called
42 dFree (_data
,_anum
* sizeofT
);
47 void dArrayBase::_setSize (int newsize
, int sizeofT
)
49 if (newsize
< 0) return;
50 if (newsize
> _anum
) {
51 if (_data
== this+1) {
52 // this is a no-no, because constructLocalArray() was called
53 dDebug (0,"setSize() out of space in LOCAL array");
55 int newanum
= roundUpToPowerOfTwo (newsize
);
56 if (_data
) _data
= dRealloc (_data
, _anum
*sizeofT
, newanum
*sizeofT
);
57 else _data
= dAlloc (newanum
*sizeofT
);
64 void * dArrayBase::operator new (size_t size
)
70 void dArrayBase::operator delete (void *ptr
, size_t size
)
76 void dArrayBase::constructLocalArray (int __anum
)