delete[] without new[]?

This is a discussion on delete[] without new[]? within the C++ Programming forums, part of the General Programming Boards category; Is there ever a case when I should use delete[] when I have not used new[] to allocate memory?...

  1. #1
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    delete[] without new[]?

    Is there ever a case when I should use delete[] when I have not used new[] to allocate memory?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    no..
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If osmeone else does the new[] for you?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    82
    Could he mean if there is a new[] inside a conditional? At which point this might happen:
    Code:
    int* ptr_var = 0;
    
    //... possibility of ptr_var = new int[SIZE]
    
    delete [] ptr_var;

  5. #5
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    I mean that or anything that you can think of.

    Can you explain what you mean by "new[] inside a conditional"?

  6. #6
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Quote Originally Posted by ChadJohnson
    I mean that or anything that you can think of.

    Can you explain what you mean by "new[] inside a conditional"?
    Whether the allocation was based on a condition. But that still means the delete has a corresponding new...

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Well, just like delete, you can safely delete[] on a NULL pointer.
    Code:
    int main(void)
    {
    	int* a = NULL;
    	delete[] a;
    	return 0;
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete[] problem with release config...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-21-2006, 11:37 AM
  2. Delete[] Error...
    By XSquared in forum C++ Programming
    Replies: 16
    Last Post: 08-06-2005, 01:29 AM
  3. delete[] or delete?
    By X PaYnE X in forum C++ Programming
    Replies: 7
    Last Post: 03-30-2005, 03:16 PM
  4. Memory issue with new[] and delete[]
    By Zarkhalar in forum C++ Programming
    Replies: 24
    Last Post: 08-07-2004, 08:45 AM
  5. delete and delete[]
    By Hunter2 in forum C++ Programming
    Replies: 13
    Last Post: 06-26-2003, 05:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21