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. Whats is difference between ::malloc and malloc , ::free and free and ::realloca and realloc in qMalloc ,qFree,qRealloc
Forum Updated to NodeBB v4.3 + New Features

Whats is difference between ::malloc and malloc , ::free and free and ::realloca and realloc in qMalloc ,qFree,qRealloc

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 4 Posters 2.2k Views 3 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 Enthusiast
    wrote on last edited by
    #1

    In file corelib/global/qglobal.cpp of QtCore

    What is difference between

    Version one
    void *qMalloc(size_t size) { return ::malloc(size); }
    1950 void qFree(void *ptr) { ::free(ptr); }
    1951 void *qRealloc(void *ptr, size_t size) { return ::realloc(ptr, size); }

    Version 2

    Void* qMalloc(size_t sz) {return malloc(sz);}
    void qFree(void* ptr) {free(ptr);}
    void* qRealloc(void* ptr, size_t sz) {return realloc(ptr, sz);}

    Are they same

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The double column operator is called the scope-resolution operator. When used like that it will resolve the malloc symbol starting at the global namespace.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Did not get that will that if you could explain more by example

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          :: = scope-resolution operator. The name.

          void someclass::func() {
          cow(); // this looks in someclass for cow() and then global
          }

          void someclass::func() {
          ::cow(); // this looks in global first, then in class to find cow()
          }

          so its a way of saying, Im talking about the global one or please look for a global version first.

          1 Reply Last reply
          3
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by Qt Enthusiast
            #5

            but as I understand we do have nor definition our own malloc defined this the following will be same

            Version one
            void *qMalloc(size_t size) { return ::malloc(size); }
            1950 void qFree(void *ptr) { ::free(ptr); }
            1951 void *qRealloc(void *ptr, size_t size) { return ::realloc(ptr, size); }

            Version 2

            Void* qMalloc(size_t sz) {return malloc(sz);}
            void qFree(void* ptr) {free(ptr);}
            void* qRealloc(void* ptr, size_t sz) {return realloc(ptr, sz);}

            jsulmJ 1 Reply Last reply
            0
            • Q Qt Enthusiast

              but as I understand we do have nor definition our own malloc defined this the following will be same

              Version one
              void *qMalloc(size_t size) { return ::malloc(size); }
              1950 void qFree(void *ptr) { ::free(ptr); }
              1951 void *qRealloc(void *ptr, size_t size) { return ::realloc(ptr, size); }

              Version 2

              Void* qMalloc(size_t sz) {return malloc(sz);}
              void qFree(void* ptr) {free(ptr);}
              void* qRealloc(void* ptr, size_t sz) {return realloc(ptr, sz);}

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @Qt-Enthusiast This is done to make sure that the global one is used. Even if you don't have any other at the moment, later someone could add one. To make sure that the global one is always used you write ::malloc
              You should ask C++ related questions here: https://forum.qt.io/category/34/c-gurus
              This is a C++ question not related to Qt.

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

              1 Reply Last reply
              3
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @jsulm Moved ! :)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

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