Note: realloc() could fail, this video explains how to handle it: ruclips.net/video/skqCnhhA0ZY/видео.html. 🙂 Also note that when using dynamically allocated memory we should use free() after we are done using it, this won't matter in a small teach-a-concept demonstration like this, but in real large program it can cause a memory leak!
sure, but if it returns NULL would it not be better to store the return address to a different pointer and then determine if string will point to it? this happens more often than one would think in small embedded chips.
@@bugurme1 realloc with a NULL argument amounts to the same thing. i am saying that checking for NULL is important. you can not avoid fragmentation as long as you deal with heap instead of stack.
Yeah this video is intended for beginners, if anyone wants to learn more about handling realloc failures check out this video covering the topic: ruclips.net/video/skqCnhhA0ZY/видео.html
Note: realloc() could fail, this video explains how to handle it: ruclips.net/video/skqCnhhA0ZY/видео.html. 🙂 Also note that when using dynamically allocated memory we should use free() after we are done using it, this won't matter in a small teach-a-concept demonstration like this, but in real large program it can cause a memory leak!
Thank you, Kevin.
sure, but if it returns NULL would it not be better to store the return address to a different pointer and then determine if string will point to it? this happens more often than one would think in small embedded chips.
in that case you don't want to use realloc? just manually malloc new space and free old space?
@@bugurme1 realloc with a NULL argument amounts to the same thing. i am saying that checking for NULL is important. you can not avoid fragmentation as long as you deal with heap instead of stack.
Yeah this video is intended for beginners, if anyone wants to learn more about handling realloc failures check out this video covering the topic: ruclips.net/video/skqCnhhA0ZY/видео.html