mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Make realloc() go 100x faster on Linux/NetBSD
Cosmopolitan now supports mremap(), which is only supported on Linux and NetBSD. First, it allows memory mappings to be relocated without copying them; this can dramatically speed up data structures like std::vector if the array size grows larger than 256kb. The mremap() system call is also 10x faster than munmap() when shrinking large memory mappings. There's now two functions, getpagesize() and getgransize() which help to write portable code that uses mmap(MAP_FIXED). Alternative sysconf() may be called with our new _SC_GRANSIZE. The madvise() system call now has a better wrapper with improved documentation.
This commit is contained in:
parent
196942084b
commit
f7780de24b
71 changed files with 1301 additions and 640 deletions
|
@ -28,14 +28,14 @@ void *Calloc(size_t a, size_t b) {
|
|||
static size_t n;
|
||||
z = a * b;
|
||||
if (!p) {
|
||||
n = __granularity();
|
||||
p = mmap((void *)0x300000000000, __granularity(), PROT_READ | PROT_WRITE,
|
||||
n = getgransize();
|
||||
p = mmap((void *)0x300000000000, getgransize(), PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
|
||||
}
|
||||
if (i + z > n) {
|
||||
mmap(p + i, __granularity(), PROT_READ | PROT_WRITE,
|
||||
mmap(p + i, getgransize(), PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
|
||||
n += __granularity();
|
||||
n += getgransize();
|
||||
}
|
||||
r = p + i;
|
||||
i += z;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue