Thread: std::string - memory issue

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

    std::string - memory issue

    I have a class, and in its constructor I declare a std::string variable, buffer. It stores the contents of an input file, so this variable usually uses about 4MB.

    I've noticed that when the program exits the constructor, the memory used by this variable is still used. This variable is not a pointer, so I don't understand why the memory is not getting recycled like your usual stack variable. What's going on and what should I do?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What STL implementation (and compiler) are you using?

    Some libraries use memory pools under the hood when using default allocators.

    gg

  3. #3
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    mingw (I think 3.80). Not sure what you mean by STL implementation.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Then it's GNU's implementation.

    http://gcc.gnu.org/onlinedocs/libstd...allocator.html

    You'll want to do your own memory management, either through a custom allocator that guarentees the ::deletion of memory, or by not using std::string.

    If you're not worried about portability, then use one of the non-standard allocators that the GNU implementation provides (scroll to the bottom of the above link).

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help finding potential Memory issue
    By JoshNCSU22 in forum C Programming
    Replies: 9
    Last Post: 10-29-2008, 09:58 AM
  2. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. threads and memory issue
    By Anubhav in forum C Programming
    Replies: 6
    Last Post: 07-25-2006, 04:51 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM