Re: Memory alloc/dealloc performance
From: Tom (tom_usenet_at_hotmail.com)
Date: 03/05/04
- Next message: Jochen Kalmbach: "Re: Getting Thead ID"
- Previous message: MattC: "Re: Getting Thead ID"
- In reply to: Stephen Walch: "Memory alloc/dealloc performance"
- Next in thread: Ivan Brugiolo [MSFT]: "Re: Memory alloc/dealloc performance"
- Messages sorted by: [ date ] [ thread ]
Date: 5 Mar 2004 02:30:12 -0800
"Stephen Walch" <swalch@proposion.com> wrote in message news:<eUtYKxeAEHA.3352@TK2MSFTNGP09.phx.gbl>...
> I did some initial performance testing of my VC++ app and found that a
> pretty significant amount of time is spent in functions like this:
>
> buff = new char[buffsize];
> ...
> delete [] temp;
>
> These allocations occurs hundreds of thousands of times in a simple run and,
> unfortunately, the size is quite variable (typically from 10 to 10,000).
>
> I know that performance tuning is a big topic, but any quick suggestions as
> to how to approach optimizing a case like this? Or pointers to some good
> memory management tutorials?
The biggest performance improvement is going to come from reducing the
number of calls to new. Reuse memory (using std::vector perhaps), and
you should find a huge speed improvement. Tuning the memory allocator
itself is much more effort for much less gain...
For example, never do:
for(int i = 0; i < v.size(); ++i)
{
char* buffer = new char[v[i].size()];
//do some processing etc.
delete[] buffer;
}
but instead do:
vector<char> buffer;
for (int i = 0; i < v.size(); ++i)
{
buffer.resize(v[i].size()); //won't reallocate unless it has to.
//do some processing etc.
}
By removing memory allocations from inner loops, it is usually
possible to increase execution speed by many orders of magnitude. Use
a profiler to find the most time-consuming ones.
>From an allocator point of view, you can optimize the smaller
allocations using some kind of memory pool. A good one can be found at
www.boost.org (the Pool library).
Tom
- Next message: Jochen Kalmbach: "Re: Getting Thead ID"
- Previous message: MattC: "Re: Getting Thead ID"
- In reply to: Stephen Walch: "Memory alloc/dealloc performance"
- Next in thread: Ivan Brugiolo [MSFT]: "Re: Memory alloc/dealloc performance"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|