Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#27 arrinit crashing

John Hansen
Pavel Petrovic

I post it here, because Lugnet server does not work.
Back to our communication on error when accessing arrays:

>>> a message "File Error!" shown on the LCD for a short moment
>>> and terminated.
>> The error occured when trying to access elements of array
>> outside of the initialized range.
> I would guess that 99% of the time that you get a File Error abend in an NXT
> program it is because of trying to access an element beyond the end of the
> array.

But I am getting it when trying to allocate an array that is larger than the amount of heap available. And it seems there is no way of checking how much space remains free, so I have no way of preventing this File Error! from happening if I have a program that needs to
allocate memory during the run without knowing in advance how much it would be. The only way I see is ardously manually try how much heap there is on the start and then try to keep track of it somehow by computing the amounts eaten by dv, etc...?

To conclude: I am missing a system call/macro that can tell me how much is ok to pass to arrinit for some particular array. Or alternately, make arrinit not to crash when there is not enough memory, simply return
empty array, and I will check with arrsize whether the allocation worked out. I.e. arrinit that does not fill the array with some value... Or even another way: passing some special constant to arrinit would allocate the largest possible array that can be allocated (ideally after compacting the memory)


  • John Hansen
    John Hansen

    • assigned_to: nobody --> afanofosc_99