3 ms·
For an allocation of that size, it's likely that your system's malloc is requesting the allocation directly from the OS's virtual memory system with mmap(2), an
by pjscott 11y ago
For an allocation of that size, it's likely that your system's malloc is requesting the allocation directly from the OS's virtual memory system with mmap(2), and freeing it with munmap(2), without ever actually writing a megabyte of zeros. Smaller allocations, however, are likely to require explicit clearing since they will hardly ever require a system call. (It depends on the details of your OS and malloc, of course.)
- mortehu 11y agoThis is on Linux with glibc, and according to strace, mmap was called exactly once at startup for a ~1 MB buffer, then never again.