Thread: reallocation of heap memory

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You could implement it with realloc. The problem is it's not part of the interface the standard containers use, so they wouldn't be able to use it.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I have never in my life traced a performance problem to an expanding array that was implemented correctly. Whether copies are required or not. I think you're imagining problems that don't exist.

    If an object is expensive to copy, then that object is probably rather large, and you ought to be storing pointers (preferably, smart pointers) instead of objects.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #18
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Yeah I think I made out like I care more than I actually do. My main concern has always been that rookie programmers use realloc incorrectly.

    Sure it might be nice to have realloc available from the standard allocator in C++, but at the same time I think we're just fine without it. Those that do tend to use it are often likely to be prematurely optimising anyway.
    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. Reallocation of memory (3d dynamic matrix)
    By beta3designs in forum C Programming
    Replies: 13
    Last Post: 08-01-2011, 12:43 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. Memory allocation/reallocation
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-04-2008, 03:27 PM
  4. Memory reallocation in C++
    By spank in forum C++ Programming
    Replies: 2
    Last Post: 08-08-2007, 09:56 AM
  5. Dynamic memory reallocation
    By Gravedigga in forum C++ Programming
    Replies: 6
    Last Post: 05-15-2005, 06:39 PM