2 ms·
realloc() is very efficient in most POSIX systems (Linux included) because of the C library using mmap techniques (e.g. Glibc). As contrast, in Windows, using t
by faragon 9y ago
realloc() is very efficient in most POSIX systems (Linux included) because of the C library using mmap techniques (e.g. Glibc). As contrast, in Windows, using the realloc() function provided in the Microsoft C library, it is slow on large arrays because of not using mmap techniques (as far as I know, the only option is to use VirtualAlloc() function and tune it by hand), involving a memory copy on every resize if the allocator has no adjacent memory reserved. So this post is interesting for Windows users using large arrays involving realloc() calls (the typical way of reducing the impact of the non-optimal realloc() on systems without MMU is to do geometric space allocation, in order to reduce the number of calls to the re-allocator, e.g. when growing, instead of adding space for one element, grow 25% the size of the array).