CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 30

Threaded View

  1. #6
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Dynamic Memory Allocation Which is best?

    Using std::vector solves that problem. When there´s an exception thrown in the array handling function there will be no cleanup. std::vector will clean up its memory because the vector variable goes out of scope when an exception occurs and its destructor will release the allocated memory. boost::scoped_array may be an alternative.

    PS:
    vector´s allocation overhead will be neglectible compared to reading a file from disk. Just make sure you don´t have to reallocate multiple times. Resizing the vector to the file´s size before reading into the vector will do only one allocation.
    Last edited by GNiewerth; July 16th, 2008 at 07:42 AM.
    - Guido

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured