irrArray extension

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

irrArray extension

Post by Dareltibus »

Feature request(is that the right place? ):
a new method in "irrArray.h" for the array class:

Code: Select all

//! erase the array from "index" to "end" if option=false
/**erase the array from "index to "start" if option=true,*/
void erase(u32 index, bool option ) //no default value for "option"
{ 
       //check if was entered an invalid value
	if(index >= used)
		return;

   u32 i=0;
	if(option)
	{
		for (; i<index; ++i)
			allocator.destruct(&data[i]);
		

		for (i=0; i<(used-index); ++i)
			allocator.construct(&data[i], data[i+index]);

		
		for (; i<used; ++i)
			allocator.destruct(&data[i]);


		used-=index;
	}
	else
	{
		for (i=index; i<used; ++i)
			allocator.destruct(&data[i]);
		used=index;
	}
}
it will be included in the engine or it is not a general case? :)

This method is only optimized for deleting the array from "start to index" or from "index to end" (the latest one is the fastest).
I'm actually using it in my game. If this is not suitable for the engine itself I will put that code in code snippets.
(i'm testing it, but if someone can tell me that it is correct I'm happy twice) :)
Last edited by Dareltibus on Sun Sep 05, 2010 8:12 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, that was not the correct place. The 1.7 beta phase is gone and closed. There would be no reason to revive such an old thread. Better make a new one, as I did for you now.
However, what's the good thing of this over the existing erase(index, number) method? That one would work exactly as yours, you just need to give the correct number of elements from index to end or from start to index.
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Post by Dareltibus »

Ok thanks.

I know :) .It should be a little faster than the old one (but only in two cases)

and i have no need to check for the last element of the array before calling it, so it is also simpler in use if you need to erase exactly from the start or from the end.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, actually the same happens here as there. The second loop in the existing method is also only invoked where necessary. So I'm not sure where your method is faster, once you did the size-index calculation.
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

O_O incredible

Post by Dareltibus »

u are right :)

erase to end:

Code: Select all

u32 time0,time1,time2;
	array<u8> a,b;
	for(u32 i=0; i<40000000; i++)
	{
		a.push_back(3);
		b.push_back(3);
	}
	;
	time0=device->getTimer()->getRealTime();
	time0=device->getTimer()->getRealTime();
	a.erase(5000000,3500000);
	time1=device->getTimer()->getRealTime();
	;
	b.erase(5000000, false);
	time2=device->getTimer()->getRealTime();

	time2-=time1; //value = 1383
	time1-=time0; //value = 1385
        bool test = time2<time1 // test = true (not a real gain)


erase to start

Code: Select all

u32 time0,time1,time2;
	array<u8> a,b;
	for(u32 i=0; i<40000000; i++)
	{
		a.push_back(3);
		b.push_back(3);
	}
	;
	time0=device->getTimer()->getRealTime();
	time0=device->getTimer()->getRealTime();
	a.erase(0,3500000);
	time1=device->getTimer()->getRealTime();
	;
	b.erase(35000000, true);
	time2=device->getTimer()->getRealTime();

	time2-=time1; //value = 3146 
	time1-=time0; //value = 2185
        bool test = time2<time1 // test = false result
all values are a average on 10 tests.

ok sorry close it O_O.
I tested it only with little arrays (1000000 size). with bigger arrays my code is slower :). original code of irrlicht is 50% faster
Post Reply