Voici l'esprit de l'ancien code:Et voici l'esprit du nouveau et "moderne" C++ ;):Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 struct Personne { unsigned id; const char *nom; const char *prenom; unsigned datenaissance; }; // StringInterning allocates a string only once and keeps it in memory "forever" class StringInterning { MemoryLeaker f_memLeak; HashTpl<char,char> f_strMap; unsigned f_stat_inserts,f_stat_empties,f_stat_strings; public: StringInterning(unsigned reserve=511*1024u,unsigned primenumber=786433u,unsigned memoryLeakerBlockSize=8*1023*1024); ~StringInterning(); static const char *GetEmptyStr(); const char *Insert(const char *s,unsigned slen); const char *Insert(const string & s) {return Insert(s,s.length());} string Stats(); }; void main() { StringInterning si; ... Personne p; p.prenom = si.Insert(newvalue); ... }
Dans le code il y a une 20aine de structures du genre Personne avec en moyenne une 10aine de membres. Pour info, le dernier traitemant (ce matin) g�rait 40.901.836 pointeurs const char * pour 3.225.807 chaines distinctes r�parties dans ces structures (la DB charg�e enti�rement en m�moire).Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 struct personne { unsigned id; string nom; string prenom; unsigned datenaissance; }; void main() { ... Personne p; p.prenom = newvalue; ... }
Une fois le traitement effectu�, la m�moire du "string interning" est lib�r�e en une fois (j'aurais d� dire "fuite de m�moire control�e").
Je pense qu'il est facile de comprendre que l'usage d'un "string interning" est bien plus performant que de laisser 40.901.836 std::string g�rer chacun son petit buffer de m�moire tout seul.
�a tourne comme une horloge depuis 15 ans :zen:
Je suis tout ou�e ;)

