How is string#size implementated?
I did:
cout << sizeof(string) << endl;
is 8 on my 64bit machine which is the same as sizeof(char*) so I am
assuming the string class stores only the char*. Then how is the size
function implemented? Is it using strlen (since it is not store the actual
size or the pointer to the ending byte)?
But on this page: http://en.cppreference.com/w/cpp/string/basic_string/size
It shows the size function have a complexity of constant, so I am
confused. This page: Why is sizeof(string) == 32? tells me his string size
is larger...
I am using GCC 4.7.1 on Fedora 64 bit.
No comments:
Post a Comment