Mno, to se da snadno overit, ze...
$ cat realloc.c
#include
int main(int argc, char *argv[])
{
void *x = malloc (10000000);
malloc (10000000);
x = realloc (x, 20000000);
return 0;
}
$ make realloc
cc realloc.c -o realloc
$ ltrace -S ./realloc
[...]
__libc_start_main(0x400514, 1, 0x7fff34c36568, 0x400560, 0x4005f0
malloc(10000000
SYS_mmap(0, 0x98a000, 3, 34, 0xffffffff) = 0x7f18029f6000
<... malloc resumed> ) = 0x7f18029f6010
malloc(10000000
SYS_mmap(0, 0x98a000, 3, 34, 0xffffffff) = 0x7f180206c000
<... malloc resumed> ) = 0x7f180206c010
realloc(0x7f18029f6010, 20000000
SYS_mremap(0x7f18029f6000, 0x98a000, 0x1313000, 1, 0x1313000) = 0x7f1800d59000
<... realloc resumed> ) = 0x7f1800d59010
SYS_exit_group(0
+++ exited (status 0) +++
IMHO by kernel mremap mohl tim premapovanim i resit... Pochopitelne porad plati, ze to musi byt velky blok alokovany pres mapovani.