Absolute gem of a channel and guy. I’m happy that since starting my programming journey 5 years ago, I could follow along with this quite well.

Still, I’m going to read into using mmap() over malloc() for full program lifetime objects. It makes sense but it doesn’t feel correct.

What do you do when you want an equivalent of free()?

  • litchralee@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 day ago

    I didn’t watch the video – and YT isn’t letting me speed-read a transcript? – but generally speaking, if you have a need for memory that isn’t backed by the filesystem, and you’re writing in C, just use malloc. It’s designed for that purpose, although malloc might very well be calling to mmap to obtain an anonymous mapping under the hood. Even if you’re going to hold on to memory for the entire lifetime of a program, still use malloc in C.

    If your application does need some filesystem backing, or if you’re allocating enough memory that hugepages might be reasonable, then that’s when you’d want to use mmap.