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

Thread: about delete

  1. #1
    Join Date
    Nov 2003
    Posts
    5

    about delete

    "const char * name", is the name be deleted ?

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    I am not sure whether I understood correctly...but it depends:
    • You need to delete
      Code:
      char *p = new char[100];
      
      // Do something with 'p'
      
      delete [] p;
    • You do not need to delete
      Code:
      const char *p = "Hello World";



    [Edited]: Messed up a little bit on the first example...corrected...
    Last edited by Andreas Masur; January 30th, 2004 at 04:38 PM.

  3. #3
    Join Date
    Nov 2003
    Posts
    5

    why?

    if you dont use "delete" to free point,
    how to free the point?

  4. #4
    Join Date
    Feb 2002
    Posts
    3,788

    Re: why?

    Originally posted by herofyf
    if you dont use "delete" to free point,
    how to free the point?
    i'm not sure what you're saying here, but:

    what is newed must be deleted, what is not it doesn't. as simple as that.

  5. #5
    Join Date
    Nov 2003
    Posts
    5

    thank you!

    as title!

  6. #6
    Join Date
    Jun 2003
    Location
    Heck-:D-Hokkaido.
    Posts
    47

    Re: why?

    Originally posted by herofyf
    if you dont use "delete" to free point,
    how to free the point?
    In C++,If you use new to dynamically allocate memory, you must use delete to dealocate memory, return what you have taken to its owner. Then the freed memory may be recycled by being used for subsequent allocation, or by being returned to the operating system.
    In C, If you use malloc, then free is what you must use.
    In some cases where you implement your own "delete" and "new" especially as I see in patterns for memory management, these malloc and free are still being used very oftenly, even in C++ environment.
    I think there is no way to accomplish what you are wanting as being said in your post I quoted.
    It is just like if you buy something, you must pay money(by yens/dollars...).., you cannot pay them your memos, writing papers etc, right ?

    Regards,

    -Vu

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