Thread: Can you free memory allocated by a std::string?

  1. #16
    Join Date
    Oct 2007
    Inside my computer
    Quote Originally Posted by cpjust View Post
    Elysia, I guess you haven't finished reading those books...
    Chapter 82. Use the accepted idioms to really shrink capacity and really erase elements
    It's called the "swap-trick".
    Nope, not yet. There's a lot to read and I have several books!
    Last edited by Elysia; 05-15-2008 at 11:57 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Oct 2002
    Quote Originally Posted by matsp View Post
    1MB isn't a whole lot in a modern machine - unless of course you have LOTS of your 1MB variables.

    My real question, however, is why you can't just destroy foo and use some other variable when you need a smaller one? That seems like the obvious solution - simpler, indeed, than messing about reserving less memory in foo.

    Well, I suppose that's the question. How do I destroy foo? It's a class member and that class needs to stick around & foo *may* need to be filled again with new data? Outside of making foo point to a dynamically allocated string (i.e. string* foo = new string) just so I can delete foo; is there some other way to destroy foo?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Refer to cpjust's example in post #13.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allocate memory inside allocated memory block?
    By Heidi_Nayak in forum C Programming
    Replies: 14
    Last Post: 04-15-2009, 04:19 PM
  2. Arrays and pointers to allocated memory
    By TriKri in forum C Programming
    Replies: 19
    Last Post: 07-23-2006, 10:52 AM
  3. Where are pointers allocated in memory?
    By sparks in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2005, 12:52 PM
  4. Dynamically allocated memory
    By ^xor in forum Linux Programming
    Replies: 9
    Last Post: 06-28-2005, 11:42 AM