Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Allocating memory using calloc.

Allocating memory using calloc.

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studioperformancehelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jossion
    wrote on last edited by
    #1

    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));

    C D 2 Replies Last reply
    0
    • J jossion

      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));

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Does your application check calloc return value? Does it free 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]

      J 1 Reply Last reply
      0
      • J jossion

        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));

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • C CPallini

          Does your application check calloc return value? Does it free 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]

          J Offline
          J Offline
          jossion
          wrote on last edited by
          #4

          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;

          1 Reply Last reply
          0
          • D David Crow

            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

            J Offline
            J Offline
            jossion
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • J jossion

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              J 1 Reply Last reply
              0
              • D David Crow

                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

                J Offline
                J Offline
                jossion
                wrote on last edited by
                #7

                Thanks for the valuable information

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups