This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
CC Table Limit *Rips hair out*
Started by Xenthera, 15 June 2013 - 09:32 PMPosted 15 June 2013 - 11:32 PM
What is the table number of values limit in computercraft? Running into strange java.lang.ArrayIndexOutOfBoundsException: 256 errors
Posted 15 June 2013 - 11:38 PM
Not at all. There is no limit to sizes of tables*. take a look
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.
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.
Posted 15 June 2013 - 11:40 PM
Not at all. There is no limit to sizes of tables*. take a looklocal 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?
Posted 15 June 2013 - 11:41 PM
256. Or is it 128… Pretty sure its 256.
I believe the array Java is complaining about is the call stack.
I believe the array Java is complaining about is the call stack.
Posted 15 June 2013 - 11: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.
Posted 15 June 2013 - 11: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.
Posted 15 June 2013 - 11:44 PM
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:
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.
Posted 15 June 2013 - 11:49 PM
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.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.
Posted 15 June 2013 - 11:51 PM
I can't do that. Super seecret project. No spoilers until I release it. If I ever get to that point.
Posted 15 June 2013 - 11: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.
Posted 15 June 2013 - 11:52 PM
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.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.
Yeah. Hopefully. I'll probably sleep on it, come up with the solution, and then be happy.
Posted 16 June 2013 - 02: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.
Posted 16 June 2013 - 03: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.
Tail calls allow recursion without creating new stack levels.
Posted 16 June 2013 - 05:29 PM
It's not necessary. If you're not willing to share the code, we can't help you.
Posted 17 June 2013 - 12:57 AM
I wouldn't say never. For example: write a function that solves the Towers of Hanoi problem.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.
There are times when recursion is the best solution.
Posted 17 June 2013 - 01:25 AM
Counterargument, https://en.wikipedia.org/wiki/Towers_of_hanoi#Iterative_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.