Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / What is the value of Ian's Find Free x commands?

Author
Message
sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 17th Jun 2010 08:56 Edited at: 17th Jun 2010 08:57
No offense to Ian; however, I'm trying to figure out what the value of having the find free commands are. They seem to find a random value, so predicting what's there is rather diffcult.

I personally like the idea of this:



Noting that the clean up function can have multiple parameters added to it for Max Whatever.

If at first you dont succeed, LOWER YOUR STANDARDS.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Jun 2010 09:18
The value is, it's quicker to use that function to return a free resource number, than to have a variable which iterates through a range of numbers to find a free one. (As the more objects you have, the longer it takes to find an empty number. IanM's picks a random object as the chances of it being taken are much lower.) Also, your example of just using the next number wastes object numbers lower which have been deleted, which wastes memory.

Saying that, I still use my own function which iterates through a range as I like to recycle my objects and the loss in speed is negligible to me.

My signature is NOT a moderator plaything! Stop changing it!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 17th Jun 2010 09:42
Mobiius beat me to it, but as a side note, use an array to store the "random" object ID's so you can group them or whatever.

Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 17th Jun 2010 10:44 Edited at: 17th Jun 2010 11:03
I had an idea for a fast and effective one. The idea is that you keep a variable to the last used object. When you create a new one, just use the number after the last used one. If any objects are deleted, add object number to an array. Then, if the array is empty, use the other method to find object numbers, otherwise, pop the last item out of the array and use it.

This can use all object numbers without spaces, and can do it all in constant time - none of this iteration and stuff.

I'd provide some code but I'm on my iPod.


[edit]
Ok here we go. Untested btw.



"everyone forgets a semi-colon sometimes." - Phaelax
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Jun 2010 15:14
zotoaster, that works but it's horrendously slow. Every time you add a new object it copies the entire array to a new location in memory.

If you want to do that, predefine your array size, or increment it in blocks of a thousand or so.

sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 17th Jun 2010 16:02
Ok, So I guess I don't understand how adding 1 to a number is slower than finding a new number, and testing to make sure it's unused, and then have the possibility of repeating the process.

Any light on that?

If at first you dont succeed, LOWER YOUR STANDARDS.
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 17th Jun 2010 16:42
BatVink,

Damn, didn't know DBP was that inefficient. I thought it would do that kind of stuff for you - you know, like every other reputable programming language

But the theory is still the same - if the array is appended in constant time, the algorithm would work in constant time.

"everyone forgets a semi-colon sometimes." - Phaelax
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Jun 2010 20:58
Quote: "IanM's picks a random object"

That depends on the particular FIND FREE XXX function that you use.

Anything in plug-in number 5 does work the way you've described, but any outside of that plug-in uses a better and faster method that picks the first free item in the range you request in constant time - the difference is that my constant 'k' is far smaller than yours, and you are also dealing with a hidden linear search.

As I get the time, I move the functions over to the new system, but the price I pay is that it's time consuming and difficult to do.

Try a speed comparison using any system you choose against FIND FREE OBJECT for example. I'd also be interested in seeing a comparison using a reuse-based method against the ones in plug-in 5 too.

Quote: "Damn, didn't know DBP was that inefficient."

I have plans to fix that, but I'm supposed to be bug fixing rather than enhancing right now.

Quote: "Any light on that?"

My functions are compiled to highly optimised machine code. DBPro does not have an optimiser, so even a very tight-appearing loop in DBPro will be slower than the equivalent C++.

Login to post a reply

Server time is: 2026-07-25 08:13:38
Your offset time is: 2026-07-25 08:13:38