Dynamic allocation in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhikutti
    New Member
    • Sep 2006
    • 5

    #1

    Dynamic allocation in C++

    Hi All,

    As per my knowledge, We can use new operator for dynamic memory allocation and free function can be used to deallocate the allocated memory.

    Free function behaves similar to Delete function in C++.

    Please let me know information about this.

    Thanks in Advance
    Radhi
  • anitajose
    New Member
    • Aug 2006
    • 11

    #2
    Originally posted by radhikutti
    Hi All,

    As per my knowledge, We can use new operator for dynamic memory allocation and free function can be used to deallocate the allocated memory.

    Free function behaves similar to Delete function in C++.

    Please let me know information about this.

    Thanks in Advance
    Radhi
    the info what u gained is right. please be specific when u write such queries. what type of info do u need regarding this?

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      If you used new then you should release the allocated memory using delete.

      You should only use free to release the allocated memory if you allocated it using malloc or calloc.

      Comment

      • suresh_punniyakkodi
        New Member
        • Aug 2006
        • 20

        #4
        Hellow,
        Your information is correct.

        new operator is used to allocate memory space at run time, and delete operator is used to free memory space at run time(Allocated memory).

        In c++,

        new operator is used inside constructor, to allocate memory space for member data or data members.
        delete operator is used inside destructor, to free memory space for member data or data members (Allocated memory).

        new operator is same as malloc, calloc in C.
        delete operator is same as free in C.

        Bye...

        Regards,
        Suresh

        Comment

        • radhikutti
          New Member
          • Sep 2006
          • 5

          #5
          Originally posted by Banfa
          If you used new then you should release the allocated memory using delete.

          You should only use free to release the allocated memory if you allocated it using malloc or calloc.

          Hi,

          Is it must that we have to use delete function to release memory allocated with new operator.

          Comment

          • suresh_punniyakkodi
            New Member
            • Aug 2006
            • 20

            #6
            Hi,

            Yes Sure, Then only memory releases. In C++, no Garbage Collection Facility. Java only have Garbage Collection facility. It means automatically memory releases at the time of program end.



            Regards,
            Suresh.

            Comment

            • babusuri
              New Member
              • Sep 2006
              • 3

              #7
              Originally posted by radhikutti
              Hi All,

              As per my knowledge, We can use new operator for dynamic memory allocation and free function can be used to deallocate the allocated memory.

              Free function behaves similar to Delete function in C++.

              Please let me know information about this.

              Thanks in Advance
              Radhi
              hi Radhi,
              if u want use delete that objeect must be created with nme operator..u can't use free insted of delete in this case..u can't use free todelete the object which is created with new operator..

              reply back..


              Thanks,
              Suri

              Comment

              Working...