Allocating memory using calloc.
-
Hi friends, I am trying to allocate around 3 sets of nearly 1.8MB of memory with calloc inside OnInitDialog() function of MFC. I used a memory leak detector tool and before I could start the worker threads I was able to see memory leaks in the lines which I used to allocate the memory mentioned above. Is there any issue in using calloc for memory allocation more than 64KB. I am using Win2000 with Visual studio 6.0 (VC++). Following is the code snippet I used. char *source_buf; unsigned long size = 9001; source_buf = (char*) calloc((size*200),sizeof(char));
-
Hi friends, I am trying to allocate around 3 sets of nearly 1.8MB of memory with calloc inside OnInitDialog() function of MFC. I used a memory leak detector tool and before I could start the worker threads I was able to see memory leaks in the lines which I used to allocate the memory mentioned above. Is there any issue in using calloc for memory allocation more than 64KB. I am using Win2000 with Visual studio 6.0 (VC++). Following is the code snippet I used. char *source_buf; unsigned long size = 9001; source_buf = (char*) calloc((size*200),sizeof(char));
Does your application check
calloc
return value? Does itfree
allocated memory? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hi friends, I am trying to allocate around 3 sets of nearly 1.8MB of memory with calloc inside OnInitDialog() function of MFC. I used a memory leak detector tool and before I could start the worker threads I was able to see memory leaks in the lines which I used to allocate the memory mentioned above. Is there any issue in using calloc for memory allocation more than 64KB. I am using Win2000 with Visual studio 6.0 (VC++). Following is the code snippet I used. char *source_buf; unsigned long size = 9001; source_buf = (char*) calloc((size*200),sizeof(char));
Since you are using MFC, why are you avoiding the
new
operator?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Does your application check
calloc
return value? Does itfree
allocated memory? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]I am not checking calloc value. But in debug mode I have watched the pointers. They are valid ones. At the same time I would like to mention that I am not freeing them anywhere in the code because this buffer is used cyclically throughout the runtime of the code by the worker thread. The pointer is duplicated for use by the worker thread. char *store_buf; store_buf=source_buf;
-
Since you are using MFC, why are you avoiding the
new
operator?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I am a bit curious about why to use new in MFC. What is the danger which is avoided by using 'new' and why such a precaution in MFC. I am almost unaware about MFC and its fundamentals.. That's why I am curious about the above issue
For integral types, there's not much difference other than the ability to track down memory leaks. For classes/objects, the
new
operator will also call the constructor."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
For integral types, there's not much difference other than the ability to track down memory leaks. For classes/objects, the
new
operator will also call the constructor."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne