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

Close

#27 arrinit crashing

open
John Hansen
None
5
2014-08-12
2007-08-17
Pavel Petrovic
No

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)

Discussion

  • John Hansen
    John Hansen
    2009-01-26

    • assigned_to: nobody --> afanofosc_99