+ 1
Is there any difference in memory allocation difference in c and c++ ?
new char[size] and malloc() have same kind of heap
8 Respostas
+ 2
Martin Taylor
I have doubt that both new/delete and malloc()/calloc()/realloc() are used together in C++ then is there any chances of failure or harmful for system.
DHANANJAY
+ 1
Martin Taylor idk if there's some confusion or misunderstanding.. but I what I meant was that this syntax should be abandoned(the one you wrote).
Array with smart pointer would be like:
std::unique_ptr<int[]> ptr(new int[5]);
That's its, no need to delete anything, it does it itself..
+ 1
Thanks all for replying.
I need to know we are using C/C++ on the same system, Is there any chance of heap related problems because of both have been used together.
Looks like smart pointers is better solution for no memory leak.
DHANANJAY
0
Best practice is smart pointers.
For example:
std::unique_ptr<int> ptr(new int(5);
Is better than memory leak prone:
int * ptr = new int(5); delete ptr; ptr = NULL;