You are not logged in.

soul_rebel

Trainee

  • "soul_rebel" is male
  • "soul_rebel" started this thread

Posts: 57

Location: Germany

  • Send private message

1

Sunday, June 19th 2005, 6:18pm

char* vs QString - sizewise

i am coding an application that manages about 12000 objects each containing about 20 strings, currently in the form of char*.
since managing char* is a pain in the ass especially when it comes to char** and splitting or joining char* i want to use qstrings and qstringlists. but my question is how much bytes does a qstring allocate by default?
since i used only pointers before, space used in declaration was minmal and all char* were initialized to new char[1] and resized when needed, if i switch to qstring, will i need more memory (considering that i am dealing with 240000 qstrings after initialization)?
or should i use qstring* and not allocate memory until actually needed?
thanks for any help!

p.s.: how do qstrings resize? can i write 3000 characters to a qstring without having to worry?
"As long as there is private property and while money is the standard of all things, I do not think that a nation can be governed either justly or happily..." - Raphael Hythloday in Utopia by Thomas More, 15th Century

Thomas

Trainee

  • "Thomas" is male

Posts: 108

Location: Socorro, New Mexico, USA

Occupation: Software Engineer

  • Send private message

2

Sunday, June 19th 2005, 7:01pm

RE: char* vs QString - sizewise

I think that you should not be afraid of "how much memory do QStrings consume" but of the fact that your char* stuff is a pain to be maintained.

It's a simple calculation. Now you have roughly 240 kB after init. With QString pointers, let's say ten times or twenty times as much - I do not have the class declaration at hand, sorry. So you'll end up with a memory consumption of less than 5 MB compared to the 240 kB before. From my point of view there is no system running with C++ libraries that cannot spend additional 5 MB.

Go for it, you'll love string handling and you will ask yourself how you did things without. At least, if you mind the QString class, use std::string. Both string classes can be resized, searched for other strings etc. without big effort.
There are 10 types of people in the world. Those that understand binary numbers and those that don't.

soul_rebel

Trainee

  • "soul_rebel" is male
  • "soul_rebel" started this thread

Posts: 57

Location: Germany

  • Send private message

3

Tuesday, June 21st 2005, 2:46pm

ok i am working on the porting process; one question in between, is there an easy way to reverse the content of a qstring? i used my own strrev funciton befor that is very simple due to chararray's nature...
"As long as there is private property and while money is the standard of all things, I do not think that a nation can be governed either justly or happily..." - Raphael Hythloday in Utopia by Thomas More, 15th Century

Thomas

Trainee

  • "Thomas" is male

Posts: 108

Location: Socorro, New Mexico, USA

Occupation: Software Engineer

  • Send private message

4

Tuesday, June 21st 2005, 2:58pm

Not from my knowledge. The annotated class index did not tell about that. But you could backwards iterate through the string, store that and return it. Voila, you'll have any string reversed like you did with plain char*, right?
There are 10 types of people in the world. Those that understand binary numbers and those that don't.

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

5

Tuesday, June 21st 2005, 3:57pm

You could probably use reverse(first, last) from <algorithm> but that wouldn't be blindingly fast...

Thomas

Trainee

  • "Thomas" is male

Posts: 108

Location: Socorro, New Mexico, USA

Occupation: Software Engineer

  • Send private message

6

Tuesday, June 21st 2005, 5:44pm

The complexity is linear (for the STL). Quote from Josuttis "The C++ Standard Template Library": Complexity: linear (numberOfElements/2 swaps or numberOfElements assignments respectively). So speed should be almost the same as for char* if one really wants to swap elements. Otherwise I would prefer the backward iterator.
There are 10 types of people in the world. Those that understand binary numbers and those that don't.