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.

AppGameKit Classic Chat / Recursion issue?

Author
Message
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Feb 2013 00:11
Has anyone tried a recursive function in tier 1?



I have never used recursion in AppGameKit so I'm not sure if there are any limitations but this crashes the program on exit.

It works if I do fewer recursions which makes me think it's some kind of stack limitation? But surly 100 recursions is not too many, I actually need thousands

I may actually have to not use recursion anyway depending on possible different device memory limitations so it may not be a big issue for my app. But if it is a bug I will report it.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Feb 2013 00:42
I think that except for trivial cases recursion is best avoided. The interpreter here is probably pushing the entire function code onto its internal stack!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Feb 2013 00:44
Recursion is sometimes the best and simplest way to solve a problem..

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Feb 2013 00:45
Sure - but you have to ensure some limits, or you're dead.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 25th Feb 2013 00:51 Edited at: 25th Feb 2013 00:53
The weird thing about this is that it finishes implying that everything went okay. Then when you try to exit the app it crashes.

After playing with the numbers it looks like 99 recursive calls is the max you can perform.

I went snooping around the interpreter code and found this:



If I'm reading this correctly (probably not) but it looks like you're allowed up to 100 recursive calls (maybe 99 recursive + the original function call) with the total size of the recursion taking up to 10240 bytes. This is v107 btw. Edit- I should point out that I don't know if the stacks are increased in size at runtime.

Quote: " But surly 100 recursions is not too many, I actually need thousands"

I agree. 1000 recursive calls isn't stretching it too far (depending on the size of your function). Ask Paul.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Feb 2013 14:40 Edited at: 25th Feb 2013 14:40
Thanks for the replies everyone.

Thanks Hodgey, I think you have found the answer to this.

I was implementing a flood fill algorithm which is a really trivial task using recursion. It's probably a good idea not to use recursion anyway since some lower end devices may not have the memory required.

Thanks.

Login to post a reply

Server time is: 2024-05-02 12:03:35
Your offset time is: 2024-05-02 12:03:35