Determine size of dynamically allocated memory in C

There is no standard way to find this information. However, some implementations provide functions like msize to do this. For example:

  • _msize on Windows
  • malloc_size on MacOS
  • malloc_usable_size on systems with glibc

Keep in mind though, that malloc will allocate a minimum of the size requested, so you should check if msize variant for your implementation actually returns the size of the object or the memory actually allocated on the heap.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)