2013年9月3日星期二

linux development process release memory problems

First, I see through the top of my program's memory usage

1. I use the first method for space and then delete the release, can be restored to use when just entering the program memory size
2., but if you use the second method, the application and then delete released, memory usage does not come down
3. If I put char data [9]; instead char data [1024]; delete the second method can successfully release the memory

above phenomenon is why? Memory fragmentation do? My demand is only 9 bytes, how to use the memory can be freed too?

# include

# define MEMLEN 1024 * 1024
class hugedata {
public:
hugedata () {}
char data [9]; / / here if 1024 following the second method can be freed delete Memory
};


int main ()
{
/ / The first method
getchar ();
hugedata * d = new hugedata [MEMLEN];
getchar ();
delete [] d;
getchar ();

/ * / / The second method
getchar ();
hugedata * d [MEMLEN];
for (long i = 0; i {
d [i] = new hugedata ();
}
getchar ();
for (long i = 0; i {
delete d [i];
}
getchar ();
* /
return 0;
}
------ Solution ----------------------------------- ---------
application layer memory pool is to solve this problem.
------ For reference only -------------------------------------- -
glibc memory allocation algorithm, the equivalent of the memory pool, fragmented memory caches together, does not immediately switch to the system.
------ For reference only - -------------------------------------
can use valgrind to troubleshoot memory leaks, very intuitive
------ For reference only -------------------------------------- -


Will I fit this requirement should be how to solve a lot I need to use (100W or so months), relatively small number of bytes of memory (7 bytes or so)
The above method will cause the system reclaims memory I do not know how to solve it
------ For reference only ---------------- -----------------------



experts can give you ideas? QT libraries currently support this feature?

没有评论:

发表评论