wxString vs wxArrayString vs wxString array Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

wxString vs wxArrayString vs wxString array

Post by Marcus Frenkel » Sat Jun 20, 2009 9:02 am

Hi,

I would like to double check which one of these take more memory and can be accessed faster:

1) 100 wxString variables
2) wxArrayString with 100 wxString variables as elements
3) wxString array with 100 wxString variables as elements

Thank you!
Marcus

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Sat Jun 20, 2009 10:28 am

1. Totally stupid (unreadable code, performance gain ungaranted).
2. More versatile, dynamic, but greedy.
3. Static, not so greedy.

stevelam
Earned some good credits
Earned some good credits
Posts: 114
Joined: Fri Apr 14, 2006 11:01 am

Post by stevelam » Sat Jun 20, 2009 10:38 am

I don't mean to seem negative, but you could always test and find out, I would be very surprised if with 100 strings that there was a major difference (apart from the code nightmare that 100 individual variables would bring)! According to the wxArrayString docs:
but the access time to the elements is constant ... it is also very size efficient and doesn't take more space than a C array wxString[] type
So given its extra versatility it seems like wxArraySting would be the best option.

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Sat Jun 20, 2009 2:33 pm

Best of both Worlds:

std::array<wxString, 100> myArray;

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Sat Jun 20, 2009 11:58 pm

Another option:

std::vector<wxString> myVector;

Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel » Sun Jun 21, 2009 8:47 am

I want to let you know that having different names for all strings is not a problem at all in my case. In fact it will be more readable for me since I will load them with certain language file and it will be more easier to know which string to put where.

Therefore, the only thing I'm focused is the memory consumption and access speed. I used number 100 as an example, it may be much more as the code grows.

If having different string rather than array is more faster and less memory greedy I will go this way.

Thank you very much!
Marcus

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Sun Jun 21, 2009 10:45 am

If performance is really important for you, i would suggest not to use wxString, but rather string, or char*.
A framework is definitely not a good solution for that.
And a char* array is really a better solution than X unconnected char* variables.

I don't know what are your aims, but it must be very very specific. Considering process speed capacity of nowadays processors and other hardware, it's theoritically sufficient enough to use in a real time industrial environment without a RT kernel (i said "theoritically" fast enough, it cannot replace a real RT kernel).

User avatar
doublemax
Moderator
Moderator
Posts: 15275
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Sun Jun 21, 2009 11:54 am

the memory usage of all given solutions are pretty much the same as they all use wxString internally, the surrounding container (wxArray, wxArraystring etc.) is pretty much neglectable. Same goes for access speed.

Some more things to consider:
In wx2.8 one wxChar uses 2 (MSW) or 4 (Linux, OSX) bytes.
In wx2.9 wxString uses UTF-8 representation internally, so for ascii-strings this reduces memory usage a lot, but operations that work on individual characters inside the string are slower.

OTOH an empty wxString already uses 40 bytes (MSW, VC7, may be slightly different on other platform/compiler) which can be an issue if you have lots of small strings.

For speed optimization it also depends a lot on what kind of operations you perform on the strings.
Use the source, Luke!

Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel » Sun Jun 21, 2009 12:16 pm

Thanks a lot to everyone. It's much more clear to me know.

Marcus

Post Reply