Commit 9e1eb1e6 authored by cutealien's avatar cutealien

Revert r2939 (allocation strategy scheme for arrays). Which means old (slow?)...

Revert r2939 (allocation strategy scheme for arrays). Which means old (slow?) speed for now. Reason is that 
assignment would otherwise depend on allocation strategy which isn't a good idea. Also some problems due to 
default template parameters which got ignored in copy-constructor and operator= which caused those functions 
not to be called. 


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2946 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 7c8293ef
......@@ -213,7 +213,10 @@ namespace scene
//! holds a associative list of named quaternions
struct SMD3QuaternionTagList
{
SMD3QuaternionTagList () {}
SMD3QuaternionTagList ()
{
Container.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE );
}
// construct copy constructor
SMD3QuaternionTagList( const SMD3QuaternionTagList & copyMe )
......@@ -270,7 +273,7 @@ namespace scene
}
private:
core::array < SMD3QuaternionTag, core::irrAllocator<SMD3QuaternionTag>, core::irrAllocStrategySafe > Container;
core::array < SMD3QuaternionTag > Container;
};
......
......@@ -77,7 +77,7 @@ namespace quake3
// some useful typedefs
typedef core::array< core::stringc > tStringList;
typedef core::array< video::ITexture*, core::irrAllocator<video::ITexture*>, core::irrAllocStrategySafe > tTexArray;
typedef core::array< video::ITexture* > tTexArray;
// string helper.. TODO: move to generic files
inline s16 isEqual ( const core::stringc &string, u32 &pos, const c8 *list[], u16 listSize )
......@@ -573,7 +573,7 @@ namespace quake3
// string database. "a" = "Hello", "b" = "1234.6"
struct SVarGroup
{
SVarGroup () {}
SVarGroup () { Variable.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); }
virtual ~SVarGroup () {}
u32 isDefined ( const c8 * name, const c8 * content = 0 ) const
......@@ -617,16 +617,19 @@ namespace quake3
}
core::array < SVariable, core::irrAllocator<SVariable>, core::irrAllocStrategySafe > Variable;
core::array < SVariable > Variable;
};
//! holding a group a variable
struct SVarGroupList: public IReferenceCounted
{
SVarGroupList () {}
SVarGroupList ()
{
VariableGroup.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE );
}
virtual ~SVarGroupList () {}
core::array < SVarGroup, core::irrAllocator<SVarGroup>, core::irrAllocStrategySafe > VariableGroup;
core::array < SVarGroup > VariableGroup;
};
......
......@@ -109,62 +109,11 @@ public:
#endif
//! defines an allocation strategy
enum EAllocStrategy
enum eAllocStrategy
{
ALLOC_STRATEGY_SAFE = 0,
ALLOC_STRATEGY_DOUBLE = 1,
ALLOC_STRATEGY_SQ = 2
};
class irrAllocStrategyDouble
{
public:
//! Returns the new size of the buffer based on the current size.
const u32 getNewSize(const u32 oldSize) const
{
return oldSize + oldSize + 1;
}
//! Returns the EAllocStrategy enum of this allocation strategist.
EAllocStrategy getAllocationStrategy() const
{
return ALLOC_STRATEGY_DOUBLE;
}
};
class irrAllocStrategySafe
{
public:
//! Returns the new size of the buffer based on the current size.
const u32 getNewSize(const u32 oldSize) const
{
return oldSize + 1;
}
//! Returns the EAllocStrategy enum of this allocation strategist.
EAllocStrategy getAllocationStrategy() const
{
return ALLOC_STRATEGY_SAFE;
}
};
class irrAllocStrategySq
{
public:
//! Returns the new size of the buffer based on the current size.
const u32 getNewSize(const u32 oldSize) const
{
return oldSize * oldSize + 1;
}
//! Returns the EAllocStrategy enum of this allocation strategist.
EAllocStrategy getAllocationStrategy() const
{
return ALLOC_STRATEGY_SQ;
}
ALLOC_STRATEGY_SQRT = 2
};
......
......@@ -17,7 +17,7 @@ namespace core
//! Self reallocating template array (like stl vector) with additional features.
/** Some features are: Heap sorting, binary search methods, easier debugging.
*/
template <class T, typename TAlloc = irrAllocator<T>, typename TAllocStrategy = irrAllocStrategyDouble >
template <class T, typename TAlloc = irrAllocator<T> >
class array
{
......@@ -25,7 +25,8 @@ public:
//! Default constructor for empty array.
array()
: data(0), allocated(0), used(0), free_when_destroyed(true), is_sorted(true)
: data(0), allocated(0), used(0),
strategy(ALLOC_STRATEGY_DOUBLE), free_when_destroyed(true), is_sorted(true)
{
}
......@@ -33,7 +34,8 @@ public:
//! Constructs an array and allocates an initial chunk of memory.
/** \param start_count Amount of elements to pre-allocate. */
array(u32 start_count)
: data(0), allocated(0), used(0), free_when_destroyed(true), is_sorted(true)
: data(0), allocated(0), used(0),
strategy(ALLOC_STRATEGY_DOUBLE), free_when_destroyed(true), is_sorted(true)
{
reallocate(start_count);
}
......@@ -83,6 +85,17 @@ public:
allocator.deallocate(old_data); //delete [] old_data;
}
//! set a new allocation strategy
/** if the maximum size of the array is unknown, you can define how big the
allocation should happen.
\param newStrategy New strategy to apply to this array. */
void setAllocStrategy ( eAllocStrategy newStrategy = ALLOC_STRATEGY_DOUBLE )
{
strategy = newStrategy;
}
//! Adds an element at back of array.
/** If the array is too small to add this new element it is made bigger.
\param element: Element to add at the back of the array. */
......@@ -121,7 +134,18 @@ public:
const T e(element);
// increase data block
const u32 newAlloc = allocatorStrategy.getNewSize(used);
u32 newAlloc;
switch ( strategy )
{
case ALLOC_STRATEGY_DOUBLE:
newAlloc = used + 1 + (allocated < 500 ?
(allocated < 5 ? 5 : used) : used >> 2);
break;
default:
case ALLOC_STRATEGY_SAFE:
newAlloc = used + 1;
break;
}
reallocate( newAlloc);
// move array content and construct new element
......@@ -225,6 +249,8 @@ public:
//! Assignment operator
void operator=(const array<T>& other)
{
strategy = other.strategy;
if (data)
clear();
......@@ -542,7 +568,7 @@ private:
u32 allocated;
u32 used;
TAlloc allocator;
TAllocStrategy allocatorStrategy;
eAllocStrategy strategy:4;
bool free_when_destroyed:1;
bool is_sorted:1;
};
......
......@@ -147,6 +147,7 @@ void CQuake3ShaderSceneNode::loadTextures( io::IFileSystem * fileSystem )
}
// clear all stages and prefill empty
Q3Texture.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE );
Q3Texture.clear();
for ( i = 0; i != Shader->VarGroup->VariableGroup.size(); ++i )
{
......
......@@ -59,7 +59,10 @@ private:
SQ3Texture () :
TextureIndex ( 0 ),
TextureFrequency(0.f),
TextureAddressMode( video::ETC_REPEAT ) {}
TextureAddressMode( video::ETC_REPEAT )
{
Texture.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE );
}
quake3::tTexArray Texture;
......@@ -68,7 +71,7 @@ private:
video::E_TEXTURE_CLAMP TextureAddressMode; // Wrapping/Clamping
};
core::array< SQ3Texture, core::irrAllocator<SQ3Texture>, core::irrAllocStrategySafe > Q3Texture;
core::array< SQ3Texture > Q3Texture;
void loadTextures ( io::IFileSystem * fileSystem );
void addBuffer ( scene::SMeshBufferLightMap * buffer );
......
Test suite pass at GMT Sat Nov 21 23:41:55 2009
Test suite pass at GMT Mon Nov 30 14:06:12 2009
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment