Vai al contenuto

Some questions about memory allocation

Home Forum Controllori SlimLine e Netsyst (LogicLab) Some questions about memory allocation

Stai visualizzando 4 post - dal 1 a 4 (di 4 totali)
  • Autore
    Post
  • #45574
    George
    Partecipante

    I am working on SlimLine Cortex M7 with firmware SFW198C200 and I have some questions.

    1.What is the maximum size of allocated memory by calling SysMAlloc or SysRMAlloc. I tested SysMAlloc with size > 4095 and returns null.

    2. How many times in a program i can call SysMAlloc.

    3. Is there any example on using SysRMAlloc? (ambiguity about pointer type declaration.. @UDINT, UDINT.

    #45577
    Sergio Bertana
    Amministratore del forum

    SysMAlloc has 4096 bytes of reserved memory, every time the function is called the specified amount of memory is subtracted from the total memory available. The function returns the pointer to the allocated memory (Type @USINT), if there’s no space available NULL is returned.

    SysMAlloc can be called all time you need a memory buffer, but remind that the allocated memory cannot be released. So every time the function is called the specified amount of memory is subtracted from the total memory available. All the SysMAlloc memory is released when user program starts.

    SysRMAlloc has 20 KBytes of reserved memory, every time the function is called the specified amount of memory is subtracted from the total memory available. A UDINT buffer is needed by the function to store the pointer to the allocated memory. If there’s no space available the UDINT buffer is set to NULL and FALSE is returned. Instead of the SysMAlloc, the allocated memory can be released by calling the SysRMFree function.

    Note that SysRMAlloc uses a completely different allocation mechanism than SysMAlloc, the allocated memory is moved run time by the operating system to optimize the memory space. This obviously causes that the pointer to the allocated memory can be modified (For this reason a buffer to store it is necessary).

    So every time a buffer allocated by SysRMAlloc is used it’s mandatory to refer to the address stored in the UDINT buffer passed to it and it’s not possible to use copies of it.

    Pointers returned by SysMAlloc e SysMAlloc are aligned so no alignment is needed, obviously when a misaligned buffer is allocated, with the next call, up to 3 bytes of memory can be lost.

    #46547
    Marcello
    Partecipante

    In merito a questo post volevo avere la conferma su due questioni.
    1) La funzione SysRMAlloc è abilitata solo per SlimLine Cortex M7 ?
    2) La memoria allocata è posta a NULL o è necessaria una pulizia mediante Sysmemset ?

    #46553
    Sergio Bertana
    Amministratore del forum

    La funzione SysRMAlloc è disponibile sia sui sistemi basati su ARM che sui sistemi basati su Cortex.

    Sui sistemi ARM (Software SFW184****) si hanno a disposizione 16KBytes di memoria, sui sistemi Cortex (Software SFW198****) si hanno a disposizione 32KBytes di memoria. Ricordo che l’area di memoria è utilizata anche dal sistema operativo quindi la dimensione disponibile per il programma utente è una parte della memoria totale.

    Sui sistemi ARM dalla versione SFW184B090, e sui sistemi Cortex dalla versione SFW198C000 la funzione SysRMalloc provvede automaticamente ad inizializzare a 0 la memoria allocata.

Stai visualizzando 4 post - dal 1 a 4 (di 4 totali)
  • Devi essere connesso per rispondere a questo topic.