Click here to Skip to main content
15,915,600 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Impact of synchronization on application performances Pin
Roger Stoltz19-Aug-08 5:51
Roger Stoltz19-Aug-08 5:51 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine19-Aug-08 6:16
Ahmed Charfeddine19-Aug-08 6:16 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine19-Aug-08 22:12
Ahmed Charfeddine19-Aug-08 22:12 
AnswerRe: Impact of synchronization on application performances Pin
Roger Stoltz19-Aug-08 22:46
Roger Stoltz19-Aug-08 22:46 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine19-Aug-08 22:53
Ahmed Charfeddine19-Aug-08 22:53 
AnswerRe: Impact of synchronization on application performances Pin
Roger Stoltz19-Aug-08 23:39
Roger Stoltz19-Aug-08 23:39 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine20-Aug-08 0:16
Ahmed Charfeddine20-Aug-08 0:16 
GeneralRe: Impact of synchronization on application performances Pin
Roger Stoltz20-Aug-08 4:33
Roger Stoltz20-Aug-08 4:33 
Regarding the user name and the critical section I just wonder if you have thought about the possibility to inform the thread that the name has changed, instead of having the thread reading the shared resource every time it needs it? This will make the user name resource thread local and you won't need any synchronization.


Here follows some thoughts that are based upon the information you've provided.
I may have interpreted your problem wrong and they may not be applicable in your situation, but perhaps you can find something useful.

Perhaps I can interest you in another article by the same author:
Optimization: Your Worst Enemy[^].

It seems to me that you're concentrating on optimizing the details in a way that you may lose the bigger picture. It's just a feeling I get from the information you've provided and I may perfectly well be wrong, but think about it. Worrying about RAM fragmentation these days, especially when you say you "allocate data from the start, I reuse them all the time". The memory manager is really clever in that aspect.


hINTModuleState wrote:
CPlayer* getPlayerByName(CString targetName)
{
  for (int i=0 --> maxPlayers)
  if(playersTab[i].getName()==targetName)
    return &playetrsTab[i];

  return NULL;
}

does much depend, if profiled, on the time spent within the string compare operations.


Well, yes, to some extent. But you have to compare it with how long it takes to iterate through the container to find it. You also have a lot of function calls that can be avoided, if you're looking for optimization.

Suppose you have a map that maps CStrings containing user names to smart pointers to objects with data for the user. Looking up the data for the user will make use of the hash table of the map class. Have a look here[^].
What I suggest is something like this:
typedef CMySmartPointerTemplate<CMyData> DataPtr_t; 
std::map<CString, DataPtr_t> NameToDataMap;

// Get the data
DataPtr_t spCurrentData = NameToDataMap[TheUserName];
if( spCurrentData )
{
    // Do whatever with the data
}
else
{
    // The name was not found, deal with it!
}
This way you don't create a CString copy on the stack as the code for the template is inline, you avoid a function call for the same reason and the lookup uses a hash table for performance, to name a few advantages.
Since the CString class has both operator<() and operator>() the std::map template hash algorithm works straight up and you don't have to provide a comparison function.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine20-Aug-08 5:54
Ahmed Charfeddine20-Aug-08 5:54 
AnswerRe: Impact of synchronization on application performances Pin
Jijo.Raj19-Aug-08 6:40
Jijo.Raj19-Aug-08 6:40 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine19-Aug-08 6:53
Ahmed Charfeddine19-Aug-08 6:53 
GeneralRe: Impact of synchronization on application performances Pin
Jijo.Raj19-Aug-08 7:19
Jijo.Raj19-Aug-08 7:19 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine19-Aug-08 21:50
Ahmed Charfeddine19-Aug-08 21:50 
GeneralRe: Impact of synchronization on application performances Pin
Cedric Moonen19-Aug-08 7:22
Cedric Moonen19-Aug-08 7:22 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine20-Aug-08 0:39
Ahmed Charfeddine20-Aug-08 0:39 
GeneralRe: Impact of synchronization on application performances Pin
Cedric Moonen20-Aug-08 1:08
Cedric Moonen20-Aug-08 1:08 
GeneralRe: Impact of synchronization on application performances Pin
Ahmed Charfeddine20-Aug-08 1:37
Ahmed Charfeddine20-Aug-08 1:37 
GeneralRe: Impact of synchronization on application performances Pin
Cedric Moonen20-Aug-08 2:11
Cedric Moonen20-Aug-08 2:11 
GeneralRe: Impact of synchronization on application performances Pin
Cedric Moonen31-Aug-08 22:35
Cedric Moonen31-Aug-08 22:35 
QuestionHow to get the full path of a file (Win32 api) Pin
ice87111719-Aug-08 4:43
ice87111719-Aug-08 4:43 
AnswerRe: How to get the full path of a file (Win32 api) Pin
David Crow19-Aug-08 5:07
David Crow19-Aug-08 5:07 
QuestionRe: How to get the full path of a file (Win32 api) Pin
led mike19-Aug-08 5:27
led mike19-Aug-08 5:27 
AnswerRe: How to get the full path of a file (Win32 api) Pin
ice87111720-Aug-08 19:26
ice87111720-Aug-08 19:26 
AnswerRe: How to get the full path of a file (Win32 api) Pin
Member 419459319-Aug-08 7:40
Member 419459319-Aug-08 7:40 
QuestionCString Format Help Pin
locoone19-Aug-08 4:41
locoone19-Aug-08 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.