why most of the programmers use malloc instead of calloc to allocate dynamic memory ?
-
I have found that there is possibility of junk data come in malloc based dynamic memory allocation. But in calloc based memory allocation does not have junk data.
But though most of programmers why use malloc instead calloc ?
-
I have found that there is possibility of junk data come in malloc based dynamic memory allocation. But in calloc based memory allocation does not have junk data.
But though most of programmers why use malloc instead calloc ?
@Qt-embedded-developer calloc overwrites allocated memory with 0 which makes it slower.
Usually the "junk" data is not a problem, or why do you care what is in the allocated memory? -
@Qt-embedded-developer calloc overwrites allocated memory with 0 which makes it slower.
Usually the "junk" data is not a problem, or why do you care what is in the allocated memory?@jsulm because i think junk data may create problem.
-
@jsulm because i think junk data may create problem.
@Qt-embedded-developer said in why most of the programmers use malloc instead of calloc to allocate dynamic memory ?:
i think junk data may create problem.
Then I suggest:
- Port to C++ classes and containers
- Initialize all your member variables correctly
- Use
new
instead ofmalloc
/calloc
This way, junk data won't be a problem, and you get better protection against other subtle bugs.