string Vs Char *

S

smreddy

I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Reddy
 
R

red floyd

smreddy said:
I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Your answer is implementation dependent.

That said, any hypothetical overhead is far, far outweighed by the
increase in reliability, security, maintability and correctness that you
get by using std::string, and not having to manage memory or pointers
yourself.
 
V

Victor Bazarov

smreddy said:
I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Very little in both cases, yet measurable. If you really care what the
overhead is, measure it. Guessing beforehand serves no practical purpose.

V
 
H

Howard

smreddy said:
I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Reddy

Does it really matter? Unless you've really got a ***lot*** of strings to
deal with, the overhead in development effort and maintenance headaches
using raw character arrays is likely to be the true deciding factor, isn't
it?

-Howard
 
S

Salt_Peter

I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Reddy
From a programmer's perspective, using char* instead of std::string
has an immense overhead.
You do have std::vector< char > available too, by the way.
Remember that char* implies fixed-size char buffer[ ]s so don't jump
to conclusion about any gain without measuring first. What goes
without arguement is the fact that char* requires more code and more
work, a lot more work.
 
G

Gianni Mariani

smreddy said:
I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

This one is the classic case of the "Mariani Minimum Complexity:

The Mariani Minimum Complexity: There exists a minimum
complexity when modelling multiple interactive systems.

Lemma 1. When modelling interactions between multiple systems, there
exists a minimum level of complexity of the interfaces where the overall
complexity of the entire system is also minimal.

In other words, if you make your interfaces too simple, your overall
solution is more complex.
 
S

Salt_Peter

I would like to know how much overhead will be there when using string
over char * and how much in terms on bytes?

Reddy

From a programmer's perspective, using char* instead of std::string
has an immense overhead.
You do have std::vector< char > available too, by the way.

Remember that char* implies fixed-size char buffer[ ]s so don't jump
to conclusion about any gain without measuring first. What goes
without arguement is the fact that char* requires more code and more
work, a lot more work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,250
Latest member
Bette22B13

Latest Threads

Top