Memory allocation

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Memory allocation

    Hi Adrian,

    I have noticed something strange with the memory allocation of emWin, please can you let me know if this is a problem or not.

    I am using the following code in my background GUI task to monitor the memory usage:

    static void

    WM_SetCallback(WM_HBKWIN, _cbBackgroundWin);

    GUI_Exec(); /* Do the background work ... Update windows etc. */
    GUI_X_ExecIdle(); /* Nothing left to do for the moment ... Idle processing */

    GUIFreeBytes = GUI_ALLOC_GetNumFreeBytes();
    GUIUsedBytes = GUI_ALLOC_GetNumUsedBytes();
    GUIFreeBlocks = GUI_ALLOC_GetNumFreeBlocks();
    GUIUsedBlocks = GUI_ALLOC_GetNumUsedBlocks();

    I have noticed then when I open a dilaog box, the memory usage increases (as one would expect), but when I close this dialog box the free memory does not return to the same amount before the window was created - it is less, yet the used memory and used blocks increase.
    If I continuously open and close this dialog window the used blocks and used bytes always gets bigger with each iteration.
    before the dialog is opened:
    GUIFreeBytes = 748272
    GUIUsedBytes = 11827164
    GUIFreeBlocks = 94
    GUIUsedBlocks = 92429

    after the dialog is closed:
    GUIFreeBytes = 748376
    GUIUsedBytes = 11827008
    GUIFreeBlocks = 96
    GUIUsedBlocks = 92427

    I this behavior correct, or is emWin gradually running out of its memory pool?
    Please can you also let me know about the question I posted sometime ago regarding the error message when an item is disabled in a dropdown box widget.

  • Hello,

    In case items are not deleted, but are created again, emWin might run out of memory. Please verify if there is a window or a Memory Device in your application which is not deleted at all or not deleted as often as it is created.

    Please note that I will respond to certain topics in the according thread.

    Best regards,
  • Thanks Adrian

    I am calling GUI_LANG_LoadCSVEx() before I create each dialog. (Each of my dialogs has its own language CSV file, which is called before calling GUI_CreateDialogBox(....) )

    If I don't call this function at all, I no longer have the problem I mentioned above.

    Is there perhaps a problem with the memory allocation of the GUI_LANG_LoadCSVEx() function, or is there a way of flushing the langue buffer upon deleting a dialog?
  • Hi Adrian,

    I want to make sure I understand this correctly, are you saying that GUI_LANG_LoadCSVEx() must not and cannot be called more than once during an application? That windows and dialogs may not have individual CSV language files, but rather the entire application must use a single CSV file for all text?


    Is this not a short coming with the way GUI_LANG_LoadCSVEx() allocates memory once it has been called? That is should be able to work multiple times across the application?
  • Ok not too much of a problem for me to change, I can see now why it was done this way.

    Perhaps the documentation should be a little more clear on this, that only one CSV can be opened otherwise you run into memory problems. In the document is says: "This function call first deletes all existing text resources", so I assumed it was ok to call GUI_LANG_LoadCSVEx() multiple times as it would delete the previous resource (and associated allocated memory)

    By the way I have found execution speed much faster if I copy the csv file into RAM from my SD card at the application start and then use the function GUI_LANG_LoadCSV().
    subsequent calls to GUI_LANG_GetText() are then executed much faster!

    Finally, I have noticed that GUI_LANG_LoadCSV() returns (available languages + 1). Is this a fault? I subtract 1 in my code as a work around for now...

  • Hello,

    Please note that there are text and csv resources. Existing text resources are deleted when loading a csv data. I will see if this explanation can be improved.

    Could you please provide me with a csv file which enables me to reproduce the function GUI_LANG_LoadCSV() returns a wrong value? Thank you in advance.

    Best regards,
  • Just a thought... If one needed to update the language files in RAM at run time, for example in a situation where a new csv file is loaded into the file system by the user.
    Would I have to re initialize emWin to load the new CSV files? Or is there another way to re-load the updated CSV file into RAM using GUI_LANG_LoadCSV()

    This could also get tricky in a multitasking environment if the file were uploaded whilst the GUI tries to access a language string