https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
s

spierce7

08/31/2021, 3:03 PM
I don’t fully understand why c functions have a free method for every single struct type. Wouldn’t a general purpose
free
method work, or heck, just using the C free method itself.
m

mbonnin

08/31/2021, 3:08 PM
Usually they do more than allocating a single struct. ffmpeg has its own memory management stuff that I can't remember because it's been a long time but automatically frees some other structs/file descriptors that could have been open during the lifetime of the "object/struct"
s

spierce7

08/31/2021, 3:13 PM
so I should probably rely on the free function, not the memScoped function?
m

mbonnin

08/31/2021, 3:13 PM
If you're using some library that has its own
foo_free()
, yes, most likely
Unless memScope {} could intercept the underlying
malloc()
calls (from inside the lib)?
But that seems unlikely + it wouldn't handle stuff like file descriptors
s

spierce7

08/31/2021, 5:17 PM
👍 Thanks
2 Views