Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing memory footprint of large unfamiliar codebase

Suppose you have a fairly large (~2.2 MLOC), fairly old (started more than 10 years ago) Windows desktop application in C/C++. About 10% of modules are external and don't have sources, only debug symbols.

How would you go about reducing application's memory footprint in half? At least, what would you do to find out where memory is consumed?

like image 208
Constantin Avatar asked Dec 14 '22 06:12

Constantin


2 Answers

Override malloc()/free() and new()/delete() with wrappers that keep track of how big the allocations are and (by recording the callstack and later resolving it against the symbol table) where they are made from. On shutdown, have your wrapper display any memory still allocated.

This should enable you both to work out where the largest allocations are and to catch any leaks.

like image 51
moonshadow Avatar answered Dec 15 '22 18:12

moonshadow


this is description/skeleton of memory tracing application I used to reduce memory consumption of our game by 20%. It helped me to track many allocations done by external modules.

like image 32
yrp Avatar answered Dec 15 '22 20:12

yrp