Before i dive into writing something more elaborated with recursion, I thought I should test it with something REALLY simple like factorial to observer memory usage when things got pushed onto the stack.. I thought I could use the nAvailFlash or kSystemNxtAvailFlash. But, they keep saying 0 or 66 respectively.

Advice?

_________________==Elizabeth Mabrey

Sun Jan 27, 2013 10:04 pm

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: Recursion

Hmm, I know that RobotC didn't support recursion before because it didn't support stack. But I am not sure if that's still true for the latest RobotC after they have revamped to 3.x. It shouldn't be too hard to write a small test to check that out though.

It shouldn't be too hard to write a small test to check that out though.

that's why I wrote the factorial recursion... that is as simple as it can get for recursion test. My question was how do I tell the stack size with robotC? You said it should not be too hard.. What would you suggest?

_________________==Elizabeth Mabrey

Mon Jan 28, 2013 1:34 pm

elizabeth.mabrey

Expert

Joined: Sun Aug 19, 2007 2:43 pmPosts: 151Location: New Jersey

Re: Recursion

mightor wrote:

I don't know what the stack size is, I recall about 256 bytes per task with a max recursion depth of about 20. Don't pin me on that, though.

= Xander

Thank you for the info... wonder if Timothy F. may verify this for us!? Better yet, is it a way to find out? I thought I could use nAvailFlash or kSystemNxtAvailFlash, but they do not seem to reflect the usage.

My students wrote a DFS simulation using iteration in RobotC. Pain in the neck to say the least. They wrote the NQueen and Huffman Coding w/ MS Visual C.... they all work beautifully. But, now we are curious to see if it is doable in RobotC. Not that we want to port nqueen and huffman coding, but to rewrite the dfs with recursion instead. So, before I even suggest to them to rewrite it in recursion, I hate to have them shoot in the dark and spend time on it but come to find out it is not doable. In order to minimize the stack size, their structure is extremely compact already... almost no bits are wasted. However, to be able to monitor the stack size will be greatly helpful.

_________________==Elizabeth Mabrey

Mon Jan 28, 2013 1:45 pm

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: Recursion

elizabeth.mabrey wrote:

MHTS wrote:

It shouldn't be too hard to write a small test to check that out though.

that's why I wrote the factorial recursion... that is as simple as it can get for recursion test. My question was how do I tell the stack size with robotC? You said it should not be too hard.. What would you suggest?

I am assuming if the stack is overflowing, it will throw an exception and terminate your program. If that's the case, you can get an idea of how big the stack is by slowly increasing the N of your N-factorial program. The stack use of your program is proportional to the depth of the recursion and the depth of the recursion is determined by N.

Mon Jan 28, 2013 1:58 pm

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: Recursion

elizabeth.mabrey wrote:

My students wrote a DFS simulation using iteration in RobotC. Pain in the neck to say the least. They wrote the NQueen and Huffman Coding w/ MS Visual C.... they all work beautifully. But, now we are curious to see if it is doable in RobotC. Not that we want to port nqueen and huffman coding, but to rewrite the dfs with recursion instead. So, before I even suggest to them to rewrite it in recursion, I hate to have them shoot in the dark and spend time on it but come to find out it is not doable. In order to minimize the stack size, their structure is extremely compact already... almost no bits are wasted. However, to be able to monitor the stack size will be greatly helpful.

Are your students in high school? Those are pretty advanced for high school students. BTW, what is DFS? Distributed File System? Sorry, I am an OS guy. That's what comes to mind. Probably not since I can't imagine why one would write a file system on the Mindstorms.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum