Do you program professionally now or develop apps etc?
post
replies:
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.
all 3 comments