Determine size of dynamically allocated memory in C

后端 未结 15 2496
孤街浪徒
孤街浪徒 2020-11-22 06:15

Is there a way in C to find out the size of dynamically allocated memory?

For example, after

char* p = malloc (100);

Is there

15条回答
  •  轮回少年
    2020-11-22 07:02

    Note: using _msize only works for memory allocated with calloc, malloc, etc. As stated on the Microsoft Documentation

    The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc.

    And will throw an exception otherwise.

    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/msize?view=vs-2019

提交回复
热议问题