Determine size of dynamically allocated memory in C

后端 未结 15 2299
孤街浪徒
孤街浪徒 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 06:54

    comp.lang.c FAQ list · Question 7.27 -

    Q. So can I query the malloc package to find out how big an allocated block is?

    A. Unfortunately, there is no standard or portable way. (Some compilers provide nonstandard extensions.) If you need to know, you'll have to keep track of it yourself. (See also question 7.28.)

提交回复
热议问题