Thread: Dynamic arrays

  1. #16
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Its still not worth risking treating memory on a chance. Vart was spot on. If you dice with memory allocation especially in C you are dicing with IT death.
    Double Helix STL

  2. #17
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    Hmm, how can you use realloc sensibly then?

    If you use a temp variable to store the return value of realloc, and it turns out to be NULL, what can you do, as that surely implies that there isn't enough memory left to do whatever you wanted to do and therefore the program may as well quit.

    Unless I'm missing something...

  3. #18
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    The sensible thing to do would be to have your program handle the fact that memory is lacking (or that the realloc didn't work).

    This could be done by informing the user, freeing everything and exiting, or doing something else to continue execution with the amount of memory you already have.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  4. #19
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    Just a quick note on realloc. Memory allocation routnies costs alot ( in terms of processing time ). It's good practice to use realloc moderately, allocate a resonable amount of memory initially, and then increase it in steps, using realloc.
    First there was God. He was quite lonely, so he created Dennis.
    Dennis was unimpressed with God.
    So, . . . God created Brian..........Khan Klatt
    http://www.clifford.at/fun/GOD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating and freeing dynamic arrays
    By circuitbreaker in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2008, 11:18 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Dynamic (Numeric) Arrays
    By DavidB in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2006, 07:34 PM
  4. dynamic arrays and structures
    By godofbabel in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2002, 03:45 PM