Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Problem with freeing memory

Thread Tools

Re: Problem with freeing memory

Marcel Müller
Posts: n/a
Gert-Jan de Vos wrote:
>> Huh? What's wrong with this:
>> std::vector<int> v(1024);
>> c_style_foobar( &v[0], v.size() );

> All elements in v will be default initialized. This can be a
> performance
> problem for large arrays of POD types that are initialized from a C
> function.

AFAIK POD types have an empty default constructor resulting in an
undefined value at the beginning. This is nothing else than any other
allocation of raw memory.

> For this reason, I made a dynamic_array template class that
> has mostly the same interface as vector but allocates using new T,
> without initialization. This has several advantages over scoped_array:
> - STL style container
> - value type semantics

For buffers I would prefer reference or scoped semantics because the
expensive copy function is nothing that is likely to be wanted.

> - it knows its size

Absolutely. This is essential.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with libxml and Reader#expand not freeing memory szimek Ruby 0 06-22-2009 09:33 AM
memory allocation and freeing memory Rodrigo Dominguez C Programming 11 06-14-2005 11:54 PM
freeing memory Harald Kirsch Java 0 04-22-2005 09:17 AM
freeing memory Rajesh.Rapaka Java 17 04-21-2005 10:11 PM
Freeing more Virtual Memory in Compaq Presario S4000NX Bun Mui Computer Support 2 05-22-2004 08:46 PM