CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Why use delete?

  1. #1
    Join Date
    May 2012
    Location
    Australia
    Posts
    15

    Why use delete?

    My manager always telling me to use delete []. I don't know why? Can u tell me plz??? Is C is the only langz to usz delete???
    Last edited by Steve R Jones; October 1st, 2015 at 05:37 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Why use delete?

    Uh oh, this does not bode well.

    Quote Originally Posted by Yarlini Amirthanesan
    My manager always telling me to use delete []. I don't know why? Can u tell me plz?
    You should delete[] what you new[], but also read Stroustrup's FAQ on How do I deal with memory leaks?

    Quote Originally Posted by Yarlini Amirthanesan
    Is C is the only langz to usz delete?
    Your question was for C++, not C. It sounds like you're confused and clueless enough to require re-learning from the ground up. I suggest that you take some time to work through a book like Accelerated C++, starting from the beginning without skipping anything.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Why use delete?

    When buying that book also buy a new keyboard. The one you have seem to have some broken keys...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: Why use delete?

    Quote Originally Posted by Yarlini Amirthanesan View Post
    My manager always telling me to use delete []. I don't know why? Can u tell me plz??? Is C is the only langz to usz delete???

    Yarlini Amirthanesan
    Netw0rk Management | Military Communications
    Command, Control, Communzcations & Intelligence Division
    Defence Science and Technoogy Organisation

    Add: PO Box 1500
    Edinburgh, South Australia, 5611
    Tel: +61 8 738 97745
    Fax: +61 8 738 97549
    Email: [email protected]
    It's not necessary to post all this personal contact information in every post. I don't think you should refer to your employer publicly unless you represent it officially which I doubt you do here.

    Anyway note that new/delete isn't available in C. These are C++ operators.

    C++ doesn't have the automatic memory management you find in other modern languages such as Java and C#. This makes C++ more flexible but it also puts an additional burden on the programmer who must make sure everything that's allocated on the heap gets properly deleted.

    But there's relief to be had. A first simple step is to consider std::vector as an alternative to ordinary arrays. Then there are all the other containers in the standard library and the so called smart pointers like std::shared_ptr.
    Last edited by nuzzle; July 1st, 2012 at 04:05 AM.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Why use delete?

    Quote Originally Posted by Yarlini Amirthanesan View Post
    Can u tell me plz??? Is C is the only langz to usz delete???

    Yarlini Amirthanesan
    Netw0rk Management | Military Communications
    Command, Control, Communzcations & Intelligence Division
    Defence Science and Technoogy Organisation

    Add: PO Box 1500
    Edinburgh, South Australia, 5611
    Tel: +61 8 738 97745
    Fax: +61 8 738 97549
    Email: [email protected]
    You're in the communications divisions - seriously? Wow.

  6. #6
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Why use delete?

    Quote Originally Posted by GCDEF View Post
    You're in the communications divisions - seriously? Wow.
    Honestly, I'd take the post with a pinch of salt. I wouldn't be surprised if the poster's actual intent was simply to make this "Yarlini Amirthanesan" look bad, preferably professionally...

    I've never seen anyone online so eager to reveal their real identity and coordinates, unless they are actual professionals representing their company.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Why use delete?

    Quote Originally Posted by monarch_dodra
    I wouldn't be surprised if the poster's actual intent was simply to make this "Yarlini Amirthanesan" look bad, preferably professionally...
    I didn't think of that. Maybe some admin here could drop a note at that email address? Hmm...
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured