Also check realloc () if you reduce the size of allocated memory?

When you call realloc(), you should check to see if the function worked before assigning the return pointer to the pointer passed as the function parameter ...

I have always adhered to this rule.

Now you need to follow this rule when you know for sure that the memory will be truncated and not enlarged?

I have never seen him fail. Just thought if I could save a couple of instructions.

+4
source share
2 answers

realloc , , , . , malloc "" (, ). glibc:

, , , , .

, realloc . , realloc , .

+7

realloc ( realloc (3) Posix realloc) , malloc ( ), memcpy ( ), free ( ). ... (, - , malloc maitain , , , ...)

, malloc . , realloc .

, realloc : malloc, memcpy, free .

, , malloc, . , , . Linux Posix setrlimit (2) RLIMIT_AS -e.g. bash ulimit, .

, C memory management. MUSL libc ( Linux) - . Linux malloc mmap (2) ( C mmap, ).

+4

Source: https://habr.com/ru/post/1529745/


All Articles