4 ms·
But you call mmap only once per file: it gives you a pointer and then you just use the pointer normally. While for read() you have to call once per read() opera
by dyingkneepad 6y ago
But you call mmap only once per file: it gives you a pointer and then you just use the pointer normally. While for read() you have to call once per read() operation (minus some user space buffering).
- correct_horse 6y agommap is more general than memory mapping files. It "establish[es] a mapping between an address space of a process and a memory object". In particular, many allocators (malloc and friends) use mmap to get a block of memory from the OS with mmap(0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0); or similar.
- mhh__ 6y agoDo any allocators use anything else these days? D's std.experimental.allocator module is helpful for building allocators bit by bit even for eventual use in C++ or C.
- JoshTriplett 6y ago> Do any allocators use anything else these days? Yes, some allocators still support using sbrk, though that's a bad idea for security reasons (ASLR).
- jashmatthews 6y agoIIUC, glibc malloc still manages one arena with sbrk and then grabs other arenas via mmap.