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
wxString vs wxArrayString vs wxString array Topic is solved
-
- Experienced Solver
- Posts: 79
- Joined: Thu Sep 25, 2008 12:14 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:
So given its extra versatility it seems like wxArraySting would be the best option.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
-
- Experienced Solver
- Posts: 79
- Joined: Thu Sep 25, 2008 12:14 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
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
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).
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).
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.
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!
-
- Experienced Solver
- Posts: 79
- Joined: Thu Sep 25, 2008 12:14 am