Bug in GUI_ALLOC_GetNumFreeBlocks?

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

  • Bug in GUI_ALLOC_GetNumFreeBlocks?

    Dear all

    Would you be so kind as to help me understand why number of free blocks increases when number of free bytes decreases, please? I'm updating GUI via GUI_Delay. Then I'm checking the memory status as follows:

    while (true)
    {
    GUI_Delay(1);

    lgGUIFreeBytes = GUI_ALLOC_GetNumFreeBytes();
    lgGUIUsedBytes = GUI_ALLOC_GetNumUsedBytes();
    lgGUIFreeBlocks = GUI_ALLOC_GetNumFreeBlocks();
    lgGUIUsedBlocks = GUI_ALLOC_GetNumUsedBlocks();
    }

    What I've noticed is that by opening a new window, with edit widgets among others, the lgGUIFreeBlocks number increases, as shown in the attached picture.

    Thanks
    Images
    • Emwin Mem Usage in DB20.png

      15.63 kB, 1,152×379, viewed 414 times
  • Hi,

    If a used block gets freed it doesn't mean it gets also deleted. It might get re-used at a later point if it fits the number of requested bytes. This means that the number of free blocks can increase over time.

    For example, at some point there where a lot of small blocks required, now they are freed but not deleted. Then one large block gets allocated, and the number of free bytes decreases while the number of free blocks has been increased.

    Lets say each letter in the brackets is 1 byte


    1. Only small blocks where required:

    [F] [F] [F] - Number of free blocks is 3 (F), Number of used bytes 7 (U).

    2. Now the small blocks where freed and one large block was required:

    [F] [F] [F] [F] [F] [F] [F] [F] [F] [UUUUUUUUUU] - Number of free blocks is 9, Number of bytes used is 11

    At some point it might happen that there is not enough memory available to allocate one large block. At this points emWin deletes smaller free blocks (number of free blocks decreases) and puts them together into one large block.

    Regards
    Sven
    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.
  • Hi,

    The function GUI_ALLOC_SetAvBlockSize() is obsolete and no longer required.

    Regards
    Sven
    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.