using stdlib is a good practice in c++? | Sololearn: Learn to code for FREE!

using stdlib is a good practice in c++?

5th Oct 2019, 10:54 PM
Juan Esteban (N/A)
Juan Esteban (N/A) - avatar
2 ответов
+ 2
The stdlib is not necessary in C++ in most cases. The STL has a lot of containers like vectors, deque etc. that take care of the memory allocation for you. Even if you used a fixed size container you'd still use vec and reserve the memory when calling the constructor. Additionally C++ has its own free() function called delete() for objects and also RAII which makes even delete() obsolete in most cases. I can hardly imagine a case where you'd still use malloc, calloc, realloc or free except if you want to optimize your the performance of your code to the maximum. But if you need them don't be shy and use them. Just don't forget that pointers are dangerous :)
6th Oct 2019, 6:54 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 3
Depends on the application. I do not believe there any faults in using the cstdlib C language library.
6th Oct 2019, 1:30 AM
Manual - avatar