No announcement yet.

Running into errno=15 while opening/closing files

  • Filter
  • Time
  • Show
Clear All
new posts

  • Running into errno=15 while opening/closing files

    I'm using a 70DT and experiencing the infamous errno=15 (UserHeap == 22596, SysHeap == 11984) with my program.
    My program opens a lot of files and (AFAIK) closes them all when it's done with them.
    However, whenever I open a function that reads the number of lines in a file I get errno=15, but only if it's nested inside other functions.
    If I don't have it nested and print the mem_Heap() before and after execution (as below), I get the same amount before and after (22596)

    print("Before count ", mem_Heap());
    print("After  count ", mem_Heap());
    It also occurs whenever I call a similar 'reading' function in the same "nesting scope," and not whenever I call it outside of that scope.

    I've run into this problem before and it was caused by a missing 'file_Close(fileHandle)' call, but after that I tried to make it very apparent that whenever a file is open, I close it.
    So I'm having a hard time diagnosing the issue.

    It's a bit of a big project with accompanying text files, so it's hard to post here, but I don't mind zipping it up and emailing it to anyone willing to look at it.

    FWIW: I added #STACK 4096 at the top of my program and now it works, but I'd much rather know why and what 4096 even means? I tried to say #STACK 25000 and it said 4096 is the largest allowed, so I went with that...
    Last edited by TheLawlz; 25 April 2019, 03:26 AM.

  • #2

    As you may know, Stack is related to the program memory that your application consumes to execute various operations i.e. storing temporary variables.

    Basically, more operations running at the same time, more stack is consumed.

    Stack memory has a fixed value throughout your program (200 by default).

    Once you've exhausted all of your stack memory, your program will crash and this will result in the error message that you've mentioned.

    What #STACK does is it allows you to change the default stack size (200) to a value that you prefer (in your case 4096).

    Having a larger stack size basically allows you to do more things/handle larger data at a time.

    If you want to check the stack usage for the individual functions on your project, you may check the*.aux file.

    You may find the *.aux file inside the generated *.4Dwork folder.

    I hope this helps.

    Best regards,


    • #3

      Awesome, thank you for the info! I was ondering what the 4096 represents though? Is that how many "layers" on the stack there are? Does each one take XX bytes of RAM?
      It looks like each "layer" is another byte of RAM.

      Also, while reading from my text files on my touchscreen's uSD card, occasionally it will run into FE_INVALID_MBR, FE_INVALID_BR, FE_DISK_NOT_MNTD, in that order. However this doesn't affect the functionality (everything still loads correctly?), except when I reach the EOF. I know it's hitting the EOF, but that error never shows up, just the FE_INVALID_MBR and then the TS gets stuck (most likely because I have while loops trying to file_GetC but there is nothing left to get...).

      It seems like I never get EOF from file_GetC().


      • #4

        #STACK 4096 assigns 4096 bytes of program memory as stack memory.

        this video might help you understand the concept of how stack works

        Pointers and dynamic memory - stack vs heap

        As for the Error messages, I'm not really sure what causes those.

        Can you send the snippet that causes those error so I may simulate it on my end?

        Best regards,