Pi-Day, STL & Memory

Introduction

Today is March 14. For Europeans this is nothing special but in the US, where they reverse month and day, this day is written as 3.14. Which is the first 3 numbers of Pi.

STL

For a customer I do some modeling to help them create a super reusable application. This project is done in C++. The more I use C++. the more I like it, it is so much easier to do stuff than in C where you have to write everything out.

But here are also caveats. I sued the string class without really thinking. To find out later that this triggers the compiler to use the Standard Template Library. A very fine piece of C++ art that cost you memory. Lots of memory…

I compiled the application with the Keil/ARM compiler where I could read the map file afterwards to see where the memory had gone. The application was 12k, the STL took 180k…..

So… now I understood why Rhapsody has the OMString Class included….

OMString

The problem with OMString is that IBM did not include much documentation on the use of the Class. “Read the OMString.h file”….

Functions

  • GetAt(Nr)
    Gets the character at position <Nr>
  • SetAt(Nr, Char)
    Sets string position <Nr> to <Char>
  • Empty()
    Clears an OMString set the size to 0
  • GetBuffer()
    Converts the OMString to a char *
  • IsEmpty()
    Checks if the OMString is empty
  • getSize()
  • setSize()
  • resetSize()
    get or set the size of the OMString
  • getStr()
    returns the OMString
  • getDefaultBlock
  • GetBuffer
  • ReleaseBuffer
  • GetLength
    returns the length of the OMString

Operators

  • compare functions
    • <, <=, >, >=, ==, !=
      Compare two OMStrings or a string and a character array,
    • =
      Assignment, assigns a character, a char array or an OMString to another OMString
    • []
      access the OMString as an array
    • +, +=
      Add a char, char array os an OMString to another OMString

 

Constructors

You can construct an OMString with:

  • another OMString
  • An old fashioned character array
  • a character
  • a void.

 

So you can create and use an OMString very easy:

OMString ¬† ¬†MyString (“Moin moin”);
MyString+=” Auch Moin”);

It uses way less memory than the STL and gives you a lot of freedom with Strings.

Yo! Happy PiDay! And keep on modeling with Rhapsody!

Walter van der Heiden (wvdheiden@willert.de)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.