Does C know how to "free" free?

Asked 2 years ago, Updated 2 years ago, 134 views

It's possible to point at each type of pointer Who tells me how many pointers to write in an array should be released when memory is released?

When you hand over an array to a function, you hand over the array and the size of the array You don't have to tell me the size of free Then can I make a function that automatically finds out the size of my function like free?

c sizeof free pointer

2022-09-22 22:20

1 Answers

When the user calls malloc(), how much memory is allocated? When you allocate memory, it's not just about the size that you set Allocates (user-specified size + block size) to provide reliable access to memory.

When calling free, you do free with this added block size, so you don't have to specify the size of the array you want to cancel

Unfortunately, it seems difficult to define a function like free.


2022-09-22 22:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.