Improving the performance of an application that uses a lot of RWCStrings on the heap.

Article ID: 1187
Last updated: 07 Feb, 2008
Article ID: 1187
Last updated: 07 Feb, 2008
Revision: 1
Views: 2868
Posted: 01 Jan, 2000
by Dean J.
Updated: 07 Feb, 2008
by Dean J.
Problem


An application has a lot of objects that dynamically allocate and de-allocate RWCStrings within them. Quantify reports that for the most part the application spends time in the constructing and destructing of the RWCString objects calling malloc and free (locking and unlocking handle allocs) causing performance degradation. The machine has enough RAM (512 to 1 gigabyte) and has 1 Gig to 2 Gig processor. How can I improve the performance of this application?




Action


The application's performance degradation is due to a lot of allocation of small strings on the heap. SourcePro Core Tools module doesn't do any heap memory reorganization or compaction. However, we have a few ideas for you to choose to get around the performance problem.

a. Choose an alternative heap manager that can effectively manage your heap memory. An option is to use Rogue Wave?s Application Tuning Software (ATS) to improve performance of C/C++ applications. You can get a trial version and check whether it improves your application's performance.

b. If you are on Windows, set the Windows system call, HeapSetInformation, at the beginning of the main program. The HeapSetInformation function sets heap information for the specified heap. More information can be found at http://msdn.microsoft.com. This call may manage your memory efficiently.

c. Create your own string manager to manage all the RWCString objects in your application. The string manager basically creates all the RWCStrings of your application objects beforehand with a certain initial capacity, say 64, and then your application objects use the strings already created which will reduce the allocation of strings on the heap.

d. If you don't need to copy your small strings very often, create your own string class. The string class constructor allocates memory on the heap only if the string created is > 64 bytes(or some other value) otherwise the char pointer in the string class points to a buffer of fixed size. This is a cool idea that will definitely improve the performance of your application which uses lots of small strings. But it is an intrusive idea that requires you to replace your application's RWCStrings with this new string type. The basic skeleton of this new string class is something like this:

class String {
public:
  String(char* str);
  ~String(void);
private:
  char* str_;
  char buf_[64];
};
 
String::String(char* str)
{
  if (strlen(str) > 64)
    str_ = new char[strlen(str)+1];
  else
    str_ = &buf_;
 
  strcpy(str_, str);
}
 
String::~String()
{
  if (str_ != &buf_)
    delete str_;
}
This article was:   Helpful | Not helpful
Report an issue
Article ID: 1187
Last updated: 07 Feb, 2008
Revision: 1
Views: 2868
Posted: 01 Jan, 2000 by Dean J.
Updated: 07 Feb, 2008 by Dean J.

Others in this category