1 Reply Latest reply on Aug 17, 2018 2:31 AM by dezi_3554521

    Memory

      Hello,

       

      I would like to know if a behavior that I observe concerning the memory is normal or not:

       

      I made a reading of the available size of my memory before and after the call of the function

      extern wiced_result_t wiced_dct_read_lock( void** info_ptr, wiced_bool_t ptr_is_writable, dct_section_t section, uint32_t offset, uint32_t size );

       

      In the first case I observe this result :

      Before function
      ---
      sbrk heap size:91960
      sbrk current free:49144
      malloc allocated:33880
      malloc free:   8936
      TOTAL Free Memory58080

       

      After function ---
      sbrk heap size:91960
      sbrk current free:49144
      malloc allocated:33880
      malloc free:   8936
      TOTAL Free Memory58080

       

      Nothing abnormal in this case.

       

       

      However, if I have less memory in maloc free before calling the function, the memory is taken in sbrk current free and then free in malloc free.

      as shown in the following example:

       

      Before function
      ---
      sbrk heap size:91960
      sbrk current free:73720
      malloc allocated:17376
      malloc free:   864
      TOTAL Free Memory74584

       

      After function ---
      sbrk heap size:91960
      sbrk current free:69624
      malloc allocated:17376
      malloc free:   4960
      TOTAL Free Memory74584

       

      Is it normal or not ?

        • 1. Re: Memory
          dezi_3554521

          wiced_dct_read_lock call malloc, malloc function call malloc_generic, and malloc_generic call __real_malloc.

          I cant see sourse code of __real_malloc, but in function malloc_generic after allocating memory have this:

           

              curr_allocated += size;

              if ( curr_allocated > max_allocated )

              {

                  max_allocated = curr_allocated;

              }

          So, if your memory print function use max_allocated variable(what is likely to be), all fine.

          In generally, I think that malloc check if enough space available, and if not - it realloc memory pool with bigger size, so all must be ok.