Announcement

Collapse
No announcement yet.

Max program size?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ipaq3115
    replied


    I think you have to remember that you are always in the 'main' function. If you call a function from inside itself you get problems with recursion because you are asking the program to return to 'main' after it's done running 'main'. If main never returns you have an ever growing stack of 'main's that you've called.


    That's why the 'goto' works. You never leave main function, you just move around inside it. You could also put all your initialization code into a separate function so that you could simply call that function and reinitialize it that way.

    Leave a comment:


  • markl
    replied


    I was having issues with recursion because I was calling main() after I returned from the sub-program. Then I switched to File_Run and I didn't have to use mem_Free to get the program to run but it restarted on its own and I couldn't figure out why. But after looking at a sample program, I saw that they used goto redo: and that effectively reinitialized everything after the file_run. It's odd that you can't call main() without it being recursive, but you can put a goto statement right under the main() heading and that works fine. Anyhow, problem solved. Thank you for your help.

    Mark

    Leave a comment:


  • ESPsupport
    replied


    What were the other issues?

    "Any memory allocations in the main FLASH program are released, however, the stack and globals are maintained." What I need is help to know which variables need to be reinitialized.
    Any memory allocated will be lost, so things with mem_Alloc will be lost, as will memory allocated for file_LoadImageControl, file_Open, etc.

    Leave a comment:


  • markl
    replied


    Hello again,

    I have another question, as it turned out using File_Exec to run my sub-program required me to use mem_Free(hndl), to clear some ram, before it would load. This created other issues and I would like to use File_Run because I can execute the program without having to use mem_Free first, however according to the manual:
    "Any memory allocations in the main FLASH program are released, however, the stack and globals are maintained." What I need is help to know which variables need to be reinitialized. I use the statement


    hndl := file_LoadImageControl("NEWKBC~1.dat", "NEWKBC~1.gci", 1);

    but simply doing this still results in a restart. Can you point me in the right direction. The main program is very simple it just uses a few buttons to run different sub-programs.

    Thanks again for your help.

    Mark

    Leave a comment:


  • markl
    replied


    Thank you very much for the explanation, once I replaced that statement everything worked as it should.

    Mark

    Leave a comment:


  • ESPsupport
    replied


    file_Run() also returns to the next statement, the difference is whether your allocate memory is retained or lost.

    Depending on what your called function did and what you changed in your image control before you freed the handle (image_index for example), all you may need to do is reopen the image control.

    Or you may need to redisplay your screen, it really depends on your program.

    Leave a comment:


  • ipaq3115
    replied


    You're right, when a sub program exits it just keeps on going where it left off. Unless you use file_Run() which, as far as I remember, returns back to the beginning of your main program.

    Sounds like you are looking for something like this to reallocate the memory and the hndl pointer.

    hndl := file_LoadImageControl("NoName1.dat", "NoName1.gci", 1);

    That's the function that loads the image handle into ram and sets 'hndl' to point at it. You'll probably want to look at the beginning of your program for the same line so that you can get the correct filenames if they are different. I assume you are using Visi and this line has already been generated for you.

    You should be able to do this anywhere in your program that you want as long as your careful not to open it unless you're sure it has been freed with mem_Free(). To make sure that never happens you could simply always free 'hndl' before loading it again... like this.

    mem_Free(hndl);
    hndl := file_LoadImageControl("NoName1.dat", "NoName1.gci", 1);

    Anyway, I'm sure that's more advice than you were hoping for... hope it helps!

    Leave a comment:


  • markl
    replied


    OK, that's a question that brings up another question, when the program returns, it was my understanding that the program control begins at the point right after it was transferred to the sub-program.
    So in the main program:

    if (n == iWinbutton1)

    mem_Free(hndl);
    gfx_Cls();
    file_Exec(Keyboard,0);
    gfx_Cls;
    show_Main();

    Leave a comment:


  • ESPsupport
    replied


    Not sure that I have everything I need to solve this but I see

    mem_Free(hndl);

    Before the file_Exec, but I don't see you opening the handle again after you return

    Leave a comment:


  • markl
    replied


    Thanks for your reply, but yes I did see that appnote and I am still baffled. I launch the sub program like this:

    else if (n == iWinbutton21)
    gfx_Cls();
    mem_Free(hndl);
    Enable_Buttons();
    file_Exec("kbImage1.4XE",0);
    Show_Main();
    When I do I have over 14K of mem available. When I exit the sub program, I do it like this:

    else if (n == iWinbutton25)
    mem_Free(hndl);
    mem_Free(hFont2);
    mem_Free(hFont3);
    file_Close(hstrings) ;

    return;
    and I have over 14K of mem available, but instead of returning it blinks and resets. What method do you use to find out what the problem is. I have tried everything I can think of. As always thanks for your help.

    Mark

    Leave a comment:


  • ESPsupport
    replied


    file_exec and calling a loaded function are almost identical, the only difference is the layout of the arguments.

    Have you reviewed App note 4D-AN-P2005 http://www.4dsystems.com.au/appnotes/ it has an example in it.

    Leave a comment:


  • markl
    replied


    Hello:

    I am having a hard time getting my sub-programs to return without crashing the main. The first problem was that I didn't have enough memory for the main program to run. I fixed that but it is still an issue.
    The main still crashes when I return, but I have noticed that if I use file_LoadFunction, instead of file_Exec that it works a little better, does Loadfunction work differently or more effectively when returning from a sub-program than file_Exec ?

    Leave a comment:


  • ipaq3115
    replied


    Hey guys thanks for the ideas. I had been trying to do what Animilector was suggesting before but I missing that #MODE RUNFLASH command so it wasn't working. Got my program split up into a bunch of smaller files now, thanks guys!

    Leave a comment:


  • Animalector
    replied


    I reckon just make your files smaller, and have more programs.. then you don't have to worry about detail like complex memory management.. 4D have done that for you

    Andy

    Leave a comment:


  • VoiceOfRageAndRuin
    replied


    I'm having some issues with program size myself. I'm using a main program which is running in flash mode and loading sub programs with file_Run(). Firstly, when running one program from flash or ram or when using a main program and file_Run() problems seem to start occurring when the total program size + stack allocation reach around 12kbytes instead of the 15 that are supposed to be available. I thought I saw a post relating to this mentioning a new pmmc that would fix it? Next, when my total program size gets too big, there isn't any kind of warning, things just start acting weird. I try to play a wav file and I hear the driver switch on but the file doesn't play. Or I press a button and the device just resets for no reason. A memory collision causing an invalid instruction to be executed or something maybe? Finally, If my main program is running in flash, and my sub programs are called with file_Run() to run in RAM, shouldn't my main program be able to use the full 15k of flash and my sub program have the full 14k of RAM? Minus any overhead for variables and stack allocation in each of course. Just about all the problems I've been having with this thing are to do with memory allocation or context switching and variable and function addresses. A detailed description of how the memory in this thing operates would go a long way towards helping me and I think a few others here understand how the Picasso actually works.

    Leave a comment:

Working...
X