Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. why most of the programmers use malloc instead of calloc to allocate dynamic memory ?
Forum Updated to NodeBB v4.3 + New Features

why most of the programmers use malloc instead of calloc to allocate dynamic memory ?

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 3 Posters 645 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    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 ?

    jsulmJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      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 ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      3
      • jsulmJ jsulm

        @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?

        Q Offline
        Q Offline
        Qt embedded developer
        wrote on last edited by
        #3

        @jsulm because i think junk data may create problem.

        JKSHJ 1 Reply Last reply
        0
        • Q Qt embedded developer

          @jsulm because i think junk data may create problem.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by JKSH
          #4

          @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 of malloc/calloc

          This way, junk data won't be a problem, and you get better protection against other subtle bugs.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          5

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved