I have an old structure class like this: typedef vector<vector<string>> VARTYPE_T;
which works as a single variable. This variable can hold from one value over a list to data like a table. Most values are long,double, string or double [3] for coordinates (x,y,z). I just convert them as needed. The variables
are managed in a map like this : map<string,VARTYPE_T *>
where the string holds the variable name. Sure, they are wrapped in classes.
Also i have a tree of nodes, where each node can hold one of these variablemaps.
Using VS 2008 SP1 for this, i detect a lot of memory fragmentation. Checking against the stlport, stlport seemed to be faster (20% ) and uses lesser memory (30%, for my test cases).
So the question is: What is the best implementation to solve this requirement with fast an properly used memory ? Should i write an own allocator like a pool allocator. How would you do this ?
Thanks in advance,
Howie
Change
typedef vector<vector<string>> VARTYPE_T;
totypedef deque<deque<string>> VARTYPE_T;
and check if there is still memory fragmentation.By the way, how do you measure it with VS 2008 SP1 ?
Update: I know how HP handles on HP-UX memory fragmentation. After doing some search I found an interesting link Low-fragmentation Heap. This is a quote:
The low-fragmentation heap (LFH) helps to reduce heap fragmentation
. To me it is interesting since it resembles the approach of HP to memory fragmentation judging of course from its description. I think (besides using deque) it is another good idea to try and check. `Update 2: 1) Speed. You have told nothing about speed before so I don't have any guidance in order to give you some good advice. I also don't know where your program spends most of the time while executing.
If you think that it mainly spends time in converting strings to longs and doubles then you have to do this conversion only once and use it when accessing values of variables. Probably it is a good idea to store not strings but real values. For example in a union or Boost.Variant. If you think that the variable lacks indexes that let quick access to its values you should add these indexes.
2) Memory usage. Are you actually writing a server application running for days and should care a lot about its memory consumption ? Then I already told you, use
Low-fragmentation Heap
on Windows and try to use block sizes fewer then 16K. Also get rid of memory leaks. Of course check it but as far as I understandLow-fragmentation Heap
must handle you news.3) If you write a server application then std::vector sometimes is not a good choice. It allocates memory in one block. If it is more than 16K this might result in memory fragmentation.
4) Finally, look how a good report from HP-UX about memory allocations looks like (in order to find memory fragmentation):
and so on.