Jump to content




CC Table Limit *Rips hair out*


  • You cannot reply to this topic
15 replies to this topic

#1 Xenthera

  • Members
  • 170 posts

Posted 15 June 2013 - 10:32 PM

What is the table number of values limit in computercraft? Running into strange java.lang.ArrayIndexOutOfBoundsException: 256 errors

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 15 June 2013 - 10:38 PM

Not at all. There is no limit to sizes of tables*. take a look

local t = {}

for i = 1, 300 do
  table.insert(t, i)
end

print(#t)

what has the limit is the stack for function calls, each time a function is called it is added to the stack and this stack is what overflows. the main time you come across this is with recursion.

* the actual size limit to tables is the memory allocation to Minecraft. but if you manage to fill that, I think you need to revisit your data structures and think whether it really is required.

#3 Xenthera

  • Members
  • 170 posts

Posted 15 June 2013 - 10:40 PM

View Posttheoriginalbit, on 15 June 2013 - 10:38 PM, said:

Not at all. There is no limit to sizes of tables*. take a look

local t = {}

for i = 1, 300 do
  table.insert(t, i)
end

print(#t)

what has the limit is the stack for function calls, each time a function is called it is added to the stack and this stack is what overflows. the main time you come across this is with recursion.

* the actual size limit to tables is the memory allocation to Minecraft. but if you manage to fill that, I think you need to revisit your data structures and think whether it really is required.


Ooohh. Do you know what the function call stack limit is?

#4 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 15 June 2013 - 10:41 PM

256. Or is it 128... Pretty sure its 256.

I believe the array Java is complaining about is the call stack.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 15 June 2013 - 10:42 PM

as Mudkip said, 256, thats why you're getting that out of bounds error. You have recursion somewhere. If you can't find it, or find a solution post your code and we will help.

#6 Xenthera

  • Members
  • 170 posts

Posted 15 June 2013 - 10:43 PM

I know why i'm getting the error then. Going to have to work around it somehow, because the recursion in my code is completely necessary for the project i'm working on.

#7 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 15 June 2013 - 10:44 PM

View PostXenthera, on 15 June 2013 - 10:32 PM, said:

What is the table number of values limit in computercraft? Running into strange java.lang.ArrayIndexOutOfBoundsException: 256 errors

Im sure its 256.

Edit: The ninjaing is killing me!

Edit2:

View PostXenthera, on 15 June 2013 - 10:43 PM, said:

I know why i'm getting the error then. Going to have to work around it somehow, because the recursion in my code is completely necessary for the project i'm working on.

Give us the code and we will try to halp.

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 June 2013 - 10:49 PM

View PostXenthera, on 15 June 2013 - 10:43 PM, said:

I know why i'm getting the error then. Going to have to work around it somehow, because the recursion in my code is completely necessary for the project i'm working on.
I suspect that any time one feels like recursing more then, say, a dozen or so times, it's more likely one shouldn't be using recursion at all. Odds are there's another way.

#9 Xenthera

  • Members
  • 170 posts

Posted 15 June 2013 - 10:51 PM

I can't do that. Super seecret project. No spoilers until I release it. If I ever get to that point.

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 15 June 2013 - 10:52 PM

yeh I would say that recursion is not completely necessary. there are very few times that recursion is needed. Post your code and we shall help remove the recursion or if the recursion is needed turn it into a safe recursion. Well in that case we cannot help you fix the problem, you will have to figure it out yourself.

#11 Xenthera

  • Members
  • 170 posts

Posted 15 June 2013 - 10:52 PM

View PostBomb Bloke, on 15 June 2013 - 10:49 PM, said:

View PostXenthera, on 15 June 2013 - 10:43 PM, said:

I know why i'm getting the error then. Going to have to work around it somehow, because the recursion in my code is completely necessary for the project i'm working on.
I suspect that any time one feels like recursing more then, say, a dozen or so times, it's more likely one shouldn't be using recursion at all. Odds are there's another way.

Yeah. Hopefully. I'll probably sleep on it, come up with the solution, and then be happy.

#12 Hawk777

  • Members
  • 162 posts

Posted 16 June 2013 - 01:30 PM

Recursion is never necessary. You can always replace a recursive function with an iterative function and a stack implemented in general purpose storage, e.g. a table, storing what you would otherwise store in local variables and the program counter in the recursive function. The result may or may not look very nice, but it’s possible 100% of the time.

#13 diegodan1893

  • Members
  • 164 posts
  • LocationSpain

Posted 16 June 2013 - 02:37 PM

If it's completely necessary take a look on this: http://www.lua.org/pil/6.3.html

Tail calls allow recursion without creating new stack levels.

#14 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 June 2013 - 04:29 PM

It's not necessary. If you're not willing to share the code, we can't help you.

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 June 2013 - 11:57 PM

View PostHawk777, on 16 June 2013 - 01:30 PM, said:

Recursion is never necessary. You can always replace a recursive function with an iterative function and a stack implemented in general purpose storage, e.g. a table, storing what you would otherwise store in local variables and the program counter in the recursive function. The result may or may not look very nice, but it’s possible 100% of the time.
I wouldn't say never. For example: write a function that solves the Towers of Hanoi problem.
There are times when recursion is the best solution.

#16 Hawk777

  • Members
  • 162 posts

Posted 17 June 2013 - 12:25 AM

Counterargument, https://en.wikipedia...rative_solution. More generally, I fully agree that recursion is often easier to understand for certain types of problems, but I stand by my claim that it is never strictly necessary. If you don’t believe me, consider the fact that you can write an interpreter for a programming language, or even a CPU emulator, without using recursion, and then, having done so, can run recursive programs inside it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users