Why does `free` in C not take the number of bytes to be freed?

前端 未结 12 1621
情歌与酒
情歌与酒 2020-12-12 20:11

Just to be clear: I do know that malloc and free are implemented in the C library, which usually allocates chunks of memory from the OS and does it

12条回答
  •  萌比男神i
    2020-12-12 20:54

    C may not be as "abstract" as C++, but it's still intended to be an abstraction over assembly. To that end, the lowest-level details are taken out of the equation. This prevents you from having to furtle about with alignment and padding, for the most part, which would make all your C programs non-portable.

    In short, this is the entire point of writing an abstraction.

提交回复
热议问题