Page 1 of 1

Use of STL

Posted: Mon Nov 01, 2004 3:38 am
by mubashar
Hello every body :shock:

I m new to wxWidgets. i have an application already built in MFC 6.0 now i want to port all the source code in wxWidgets 2.4.2.

Now that application has much use of STL like vectors, maps, pairs, set etc etc. and i also ready in some tutor that wxWidgets do not support STL.
but i also saw a lot of code of wxWidgets on the net using STL structures and classes. i m in much confusion please show me some right path

i m using Visual Studio.Net 2003.


Thanksssss

Posted: Mon Nov 01, 2004 5:31 am
by SnakeChomp
wxWidgets is beginning to move to implementing things via STL. Taken from setup.h:

//Set wxUSE_STL to 1 to derive wxList(Foo) and wxArray(Foo) from
// std::list<Foo*> and std::vector<Foo*>, with a compatibility interface,
// and for wxHashMap to be implemented with templates.

wxWidgets did not officially use STL before because it was said to be unportable and not widely supported by all compilers. But that was then, and this is now.

That being said, you can use STL stuff in your application all you want. Go ahead and derive a class from std::vector, wxWidgets won't care. It can't care. The one thing it technically doesn't support yet is c++ RTTI, as it uses its own macro based RTTI system. Although that may be changing as well? I'm not sure on that one.

And by the way, you should port into 2.5.3 instead of 2.4.2. No reason not to. (Note "unstable" means that the API may possibly change, as in removing, changing, or adding functions. Not that it crashes or is not for production use.)

Posted: Mon Nov 01, 2004 6:02 am
by mubashar
Thanksss For you reply "SnakeChomp"

it seems that you offered me water of life :D .

but is there any efficiency leak in using STL as i aslo read on some forums and FAQs wxList is more faster then std::vector. and so on so on for other classes too.

and one more thing that i can't change libraray to 2.5.3 as i am advised 2.4.2 by our PM :shock: :shock:


Thanks anyway

Posted: Mon Nov 01, 2004 6:22 am
by HopeSeekr
regardless of what others may tell you, even if they are authoritative wx coders, from my own extensive research using real-time OS-wide profilers (notably oprofile), I can confirm that the usage of STL-specific code is far more efficient than wx's pre-ISO-C++ implementations of the same.

For instance, I recently converted all of xMule's ubiquitous wxLists to std::lists, wxMap to std::map, and wxArrays to std::vectors. Performance jumped due to these changes to about 1/20th of the CPU cycles of the wx-variants.

The only real argument for using wx variants is that some of them are 'easier'. This *is* true for one class in particular, wxString, which greatly extends the abilities of std::string; yet all the other wx ADT are about equally endowed and easy/hard to use as their ISO counterparts.

We found that wxString was still too much overhead and wrote a std::string derived wrapper that is backwards compatible with wxString functionality, but using pure ISO-c++ conventions wherever possible.

Besides, far more people willll understand/be able to suport ISO code, and ti is *far* easier to migrate away from wx if you use it ubiquitously.

Posted: Mon Nov 01, 2004 7:26 am
by mubashar
HopeSeekr wrote:from my own extensive research using real-time OS-wide profilers (notably oprofile), I can confirm that the usage of STL-specific code is far more efficient than wx's pre-ISO-C++ implementations of the same.

And what about compatibility... can i use STL for all plateforms supported by wxWidgets???

Posted: Mon Nov 01, 2004 10:43 am
by geon
can i use STL for all plateforms supported by wxWidgets???
You can use STL on all platforms that "matters". And if you are speciffically developing for a platform that don't, you probably allready have the skills needed to port an existing STL implemetation.

Posted: Mon Nov 01, 2004 1:38 pm
by Avi
Every good compiler today supports the STL library. STL classes/templates are very optimized and usually perform great. I suggest you learn how to use it, since even wxWidgets will use it. I personally know that it is supported under Linux/FreeBSD/Windows/MacOS X. I find it hard to believe you'll need more platforms than that anyway. :)

Posted: Mon Nov 01, 2004 3:41 pm
by ezequielv
Avi wrote:Every good compiler today supports the STL library. STL classes/templates are very optimized and usually perform great. I suggest you learn how to use it, since even wxWidgets will use it. I personally know that it is supported under Linux/FreeBSD/Windows/MacOS X. I find it hard to believe you'll need more platforms than that anyway. :)
What about future ports, such as Cobalt (Palm OS 6)? Not all the C++ compilers for pseudo-embedded systems have STL implementations nor will handle all required C++ template features.

Posted: Mon Nov 01, 2004 4:14 pm
by Ryan Wilcox
mubashar wrote: And what about compatibility... can i use STL for all plateforms supported by wxWidgets???
Probably. There still are brain-dead compilers out there (VC 4? OpenWatcom?) but any modern compiler should have decent STL support.

Posted: Mon Nov 01, 2004 8:39 pm
by HopeSeekr
What about future ports, such as Cobalt (Palm OS 6)?
In those cases, I would challenge the expediency of using wxWidgets in the first place. If the hardware is too dumb to support templates and std::vector, I'd *hate* to try to run any thing that even would need a wxArray :o

If it is not a hardware-specific problem, then it must be a bytecode problem. With the increasingly-dominant cross-compiler utilized for building objects for fringe environments like PalmOS, I would assume (in my naivete) that your host compiler would support ISO-C++ and produce suitable binaries for the target.

Posted: Tue Nov 02, 2004 3:00 am
by mubashar
Thanks all of you

I have got enough now NO ONE can stop me from the using STL. 8) 8) 8)

Posted: Tue Nov 02, 2004 12:06 pm
by geon
the hardware is too dumb to support templates
Templates is just a language construct. There is no way a processor could not support them. If they are not supported on a certain platform, it's because the compiler has not implemented them.

I think the gcc compiler has become quite polpular on more obscure platforms, like playstation, since it allready has great c++ support and can be modified. Probably a better alternative than to write your own compiler.