[Issue: memory device handle is increasing from some moment and mem-dev output go strange]

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

    • [Issue: memory device handle is increasing from some moment and mem-dev output go strange]

      Hello,
      I wrote the attached codes to output a string by activating the memory device function of emwin lib.
      This code seemed to work well, but as I tested it a few times, the hMem handle value returned from GUI_MEMDEV_CreateEx, began to increase at some point, and then from a moment it was out of control as if it was running out of memory and output went mess. Can someone tell me what caused this symptom?
      FYI, the function created below confirmed that GUI_MEMDEV_CreateEx() and GUI_MEMDEV_Delete() are always executed together. I thought that the memory should be released after gui_memdev_delete(), but it did not seem to be released. Symptom is like this. hMem value is increasing from some moment.

      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 5
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 6
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 5
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 6
      .....
      ...
      //did some other things in the setting ui.
      ...
      ..
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 7
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 4
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 7
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 4
      .....
      ...
      //did some other things in the setting ui.
      ...
      ..
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 9
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 10
      ...
      .....
      ...
      //did some other things in the setting ui.
      ...
      ..
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 11
      hMem = GUI_MEMDEV_CreateEx(...)
      //do gui_disp_string()
      GUI_MEMDEV_Delete(hMem) // hMem = 12
      .........

      Have you seen any similar symptoms?

      Best Regards,
      Tommy Lim
      Files
      • a.txt

        (3.96 kB, downloaded 311 times, last: )
    • Hi Tommy Lim,

      GUI_MEMDEV_CreateEx() creates a memory device and allocates the necessary memory. The number that is returned is the handle number. Handle numbers are always unique. By creating new devices, a different number is picked so that emWin can tell the memory devices apart.

      Is there any reason why you delete and recreate the device so often? Usually a memory device should only be deleted when it is not needed anymore at all, like when the associated window has been deleted.

      Have a look at this Wiki example, you can adapt it for displaying the string.

      Best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Dear Florian,
      Sorry for late response.

      Thank you for your answer in advacne.
      The reason that I delete and recreate the device was that I thought that is right for memory management like any other memory allocation scheme.
      But emWin seems not like that.
      I think you're saying to declare hMem handle as global and continue to use it without deleting it.
      What if various sizes bmp data should be printed with mem-deveice function? Do I have to declare one mem-dev handle for biggest size?

      FYI, regarding above issue, I did like this.
      -when encountered handle is too large, did as below
      GUI_Exit();//Clears emWin internal data from memory to make further calls of GUI_Init() possible.
      GUI_Init();//GUI_Init() is called again to use emWin Library again.
      // LCD-low level initialization code will be executed again at GUI_Init(), so need to check if re-initialize is ok or not.
      // To me, LCD RGB bit order was reverse, so I needed to block re-initialization of LCD at GUI_Init() to avoid instant color inversion btw Red and Blue.
      -> this way seems not right method to me, but I think I have no choice now.
      If you have good alternative, please advice me.

      Best Regards,
      Tommy Lim

      The post was edited 1 time, last by Tommy lim ().

    • Hi Tommy,

      It depends on how you want to do. A memory device is effectively a drawing container. So if you have multiple images that you want to display separately, then one device would be sufficient and it would have to have the size of the biggest image, so that all images fit into the device.

      But because a memory device is for drawing input, drawing something new will overwrite the old pixel data. So to keep multiple images pre-rendered in memory devices, you would of course need one device per image.

      You should keep the memory device in RAM as long as you need to display it. E.g. if the memory device is only needed for a specific window, you can delete the MemDev when the window is deleted.

      Creating this many memory devices only really makes sense if the decompression of the image requires too much CPU power and your hardware has enough RAM to create the memory devices. If your BMP images are uncompressed, the memory devices might not even be necessary.

      Best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.