 |
Who's Online |
 |
|
There are currently, 2 guest(s) and 0 member(s) that are online.
You are Anonymous user. You can register for free by clicking here
|
|
|
 |
| |
Coding Blog: The Great Refactor: Step 1: Replace nstrdup
Posted by HopeSeekr on Tuesday, June 22 @ 15:50:05 CDT
Contributed by HopeSeekr
Replace the local nstrdup() implementation with standard strdup() one. Primarily a performance increase, but this also has several major advantages...
First advantage: Decoupling
The biggest performance issue in xMule right now is its module interdependencies. In an oportune environment, every single .h file should include only a minimal number of files. Decoupling decreases compile time dramatically, makes programs less likely to segfault, and decreases CPU and memory usage.
Second advantage: Standardization
By using the standard strdup instead of our own implementation of nstrdup, we remove any and all unexpected behaviorisms that differ from the norm. This is incredibly noticeable when it comes to unicoding xMule, as wxChar* are handled appropriately by strdup() but get mangled with nstrdup().
Third advantage: Decrease in memory leaks:
Our nstrdup() assigned memory via new, which is overkill, because the size of the source string is always defined, and because char* has no c_tor()s or d_tor()s, yet wxChar* does. This means that unexpected behaviorisms crop up because C++ tries to free() char* and in this instance, delete[] is the appropriate mechanism.
The change(s) specified above were made at
FileRevCount
PartFile.cpp1.12516
packets.cpp1.366
BaseClient.cpp1.905
KnownFile.cpp1.494
AddFileThread.cpp1.332
Preferences.cpp1.811
UploadClient.cpp1.381
otherfunctions.cpp1.531
-->
The final results are that only PartFile.cpp needed otherfunctions.h after this decoupling effort. One out of 8, not bad for one inefficient function :-)
Compile times
Before6m27.87s
After5m 55.03s
A diff of all changes.
|
|
| |
 |
Login |
 |
|
|
Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.
|
|
|
 |
|
| "The Great Refactor: Step 1: Replace nstrdup" | Login/Create an Account | 0 comments |
|
| | The comments are owned by the poster. We aren't responsible for their content. |
|
|
|
No Comments Allowed for Anonymous, please register |
|
|