I have a set of GPS points with following recor开发者_如何转开发ds:
point_label lat lon H
FraEur3 N35.3575 E12.4617 207.39
I am thinking about suitable data representation for point label.
What is better:
class GPSPoint
{
char * label;
double lat, lon, h;
};
or
class GPSPoint
{
char label[255];
double lat, lon, h;
};
The first option has less memory consumption, but I have to write copy constructor, operator=
and destructor etc.
The second option is easier to code but has a greater memory consumption.
Which option do you recommend? I do not want use std::string
...
class GPSPoint
{
vector<char> label;
double lat, lon, h;
}
It is not string and dynamically allocable.
Well, std::string
is the solution and I can't imagine why you'd want to avoid it.
To be honest, though, I wouldn't have a label in there at all. Let your point class just contain co-ordinates; you can handle labelling outside of that logic.
In the first case, you'll need to allocate memory elsewhere for the string contents. There is absolutely no reason to prefer this to std::string.
You should be able to find documentation on the maximum length of the string to reduce the size of your fixed char array.
I sure hope you have a good reason for dismissing std::string out of hand.
精彩评论