Welcome to xMule: A P2P Client derived from eMule BerliOS Developer LogoSourceForge.net Logo


Links
- Visit the Forums!
- SF.net Project Page
- xMule Screenshots

Modules
· Home
· Content
· Downloads
· Recommend Us
· Search
· Statistics
· Top
· Topics
· Your Account

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

 
The Great Refactor 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
Nickname

Password

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.

Related Links
· More about The Great Refactor
· News by HopeSeekr


Most read story about The Great Refactor:
Our Situation


Article Rating
Average Score: 0
Votes: 0

Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad


Options

 Printer Friendly Printer Friendly


"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


PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL.
PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.05 Seconds