开发者

Windows application consumes too much memory. Any advices?

开发者 https://www.devze.com 2023-02-07 11:20 出处:网络
Visual studio 2008 application using C++ unde开发者_C百科r windows XP. Any useful advices beyond the \"always delete new objects\" advice?

Visual studio 2008 application using C++ unde开发者_C百科r windows XP.

Any useful advices beyond the "always delete new objects" advice?

Edit: Actually I am looking for some programming advices.


Depends what you mean by "consumes too much memory".

A) By design i.e. it requires to load or generate large data structures that you expect to cause problems.

In this case is it i) too much phyical memory i.e. it becomes slow because the hard drive starts swapping pages in and out or ii) too much address space i.e. it fails to allocate because it can't find a hole in the memory?

For ii) consider using 64bit builds, consider using shared memory to store large data structures, beware of fragmentation - allocate large buffers early, break up large data structures into smaller ones

B) It surprises you by using loads of memory.

Find your leaks or bugs - various profilers available or visual studio built in debug alloc hooks. Do you have any broken arithmetic for calculating buffer sizes(especially accidental int wrap around)?

Use smart pointers to manage deletion.


Assuming that you have a memory leak, there's a free solution to throw at the problem before buying/running other profiles, and that's UMDH. It can detect most memory leaks, if that's your situation.

http://support.microsoft.com/kb/268343

0

精彩评论

暂无评论...
验证码 换一张
取 消