Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Get to Know uSTL: A Lightweight STL for Symbian : Page 3

Can uSTL satisfy Symbian developers' demand for STL support? This partial STL implementation replaces template-based memory management classes with a classic 1990's object-oriented design.


advertisement
Island in the Streams
ustl::cin, ustl::cout, and ustl::cerr work mostly the same as their standard counterparts. For example:

#include <ustl.h> using namespace ustl; cout << "Hello world!" << endl; cout << 456 << ios::hex << 0x1234 << endl; cerr.format("object address: 0x%08X\n", &o);//format() is a uSTL extension

That's pretty much it for console I/O in uSTL. <fstream> classes are not implemented yet. To perform file I/O, you create a string buffer, call read_file(), and then attach a stream to it. It's ugly but gets the job done.

The major difference between ISO STL and uSTL is that the former uses a distinct allocator per specialization, whereas the latter keeps all the memory management logic in a single base class. When ISO STL containers reallocate storage, they call new[] to create more storage and then copy the elements to the new destination. This technique incurs size and speed penalties. uSTL uses a different approach. It manages memory as an opaque, typeless block, and then uses the container templates to cast it to an appropriate pointer type. I know what you're thinking: bitwise copying of objects is a no-no, and you're right. However, uSTL doesn't copy elements; it merely moves them.



What's Still Missing
I've given you the impression that uSTL is a compact, smart and clutter free version of ISO STL. This is true in most part but there are a few caveats you should take note of if you plan to port existing apps to a mobile platform. The most noticeable deviation from ISO STL is the absence of standard function objects such as greater, less, etc. Sharov's rationale for this deliberate omission doesn't sound convincing. Indeed, some of STL's abstruse features don't have a place in a tightly packed implementation but function objects and predicates are too important to be completely dismissed. Additional unimplemented features include:

  • File stream classes. This could cause porting difficulties but you can get by with read_file().
  • deque and priority_queue.
  • Heap algorithms such as push_heap(), make_heap(), etc.
  • TR1 hashed containers (now officially called "unordered containers"), like unordered_map. This isn't a major issue since many existing ISO STL implementations don't offer these yet.
  • wchar_t-oriented stream and string classes

Author's Note: Since the time of writing, uSTL 1.0 has been released. The new version is much closer to ISO STL as it provides many features that were missing from version 0.8, including fstream classes, function objects, and function adaptors (like unary_negate and unary_function)—as well as non-standard extensions such as the select1st and select2nd algorithms.

Overall, uSTL 0.8 is much closer to ISO STL than I anticipated, in spite of its peculiar design. Although it contains a subset of ISO STL, it will suit the needs of the average C++ programmer who simply needs reliable and familiar building blocks such as vector, list, sort(), remove() and cout. Considering the shoddy classes and proprietary APIs that Symbian developers use as alternatives to containers and algorithms, uSTL is light years ahead. uSTL gets a major thumbs up!



Danny Kalev is a certified system analyst and software engineer specializing in C++. He was a member of the C++ standards committee between 1997 and 2000 and has since been involved informally in the C++0x standardization process. He is the author of "The ANSI/ISO Professional C++ Programmer's Handbook" and "The Informit C++ Reference Guide: Techniques, Insight, and Practical Advice on C++."
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap