Thread: how to double an array size?

  1. #61
    Registered User
    Join Date
    Apr 2008
    Posts
    20
    well they are both array and yes they both are set to point to something. i had badwords point to a class of badwords which consist of two strings and then i have sentence point to an array of words that make up a sentence.

  2. #62
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then one or the other (or, I suppose, both) is already delete[]d when you get to the destructor. You wrote the code, so presumably you know which.

  3. #63
    Registered User
    Join Date
    Apr 2008
    Posts
    20
    hmm i believe its badwords because when i // it doesnt give me the double free error but i dont see where i deallocate it

  4. #64
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I am aware that past performance is no guarantee of future growth, but: perhaps you deallocate another pointer that you have set equal to badwords?

  5. #65
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What do you mean, you use the destructor? Do you call it explicitly? You're not supposed to do that.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #66
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    If you use a safe delete function, then you won't get the delete error.

    possibly
    Code:
    void DeletePtr(void* ptr)
    {
       delete ptr;
       ptr = 0;
    }
    
    void DeletePtrA(void* ptr)
    {
       delete []ptr;
       ptr = 0;
    }

  7. #67
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Raigne View Post
    If you use a safe delete function, then you won't get the delete error.

    possibly
    Code:
    void DeletePtr(void* &ptr)
    {
       delete ptr;
       ptr = 0;
    }
    
    void DeletePtrA(void* &ptr)
    {
       delete []ptr;
       ptr = 0;
    }
    Perhaps?

  8. #68
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    why a reference?

  9. #69
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Maybe I am the confused one at this point. What purpose does your function actually serve?

  10. #70
    Registered User
    Join Date
    Apr 2008
    Posts
    20
    well im done with this whole thing thanks for all the help you guys i got it working 100% no problems or anything thanks i learned a lot too.

  11. #71
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why a reference? If you want to change the parameter that gets passed in, how else would you do it?

  12. #72
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The best I can figure, perhaps he is of the .NET school of thought wherein things are reference counted and its a crap shoot knowing whether or not they still exist in memory until you zero them. But even at that... *shrug* who cares.

  13. #73
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    no, I never use pointer references in my code, and everything works out fine.
    those are the functions I use to free memory. I don't know, but through the debugger this works fine. Stepping through the code produces no incorrect behavior.

  14. #74
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Raigne View Post
    no, I never use pointer references in my code, and everything works out fine.
    those are the functions I use to free memory. I don't know, but through the debugger this works fine. Stepping through the code produces no incorrect behavior.
    And are the pointers equal to 0 afterwards?

  15. #75
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Raigne View Post
    no, I never use pointer references in my code, and everything works out fine.
    those are the functions I use to free memory. I don't know, but through the debugger this works fine. Stepping through the code produces no incorrect behavior.
    Okay well I'll say this once: If you use the function you posted then the variables passed in will NOT be set to null.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  4. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM