[Xapian-devel] sizeof(std::string)

Olly Betts olly at survex.com
Tue Apr 10 18:23:52 BST 2007


On Thu, Apr 05, 2007 at 03:39:57PM +0100, Olly Betts wrote:
> I've noticed that under GCC at least (I tried 2.95, 3.3, and 4.1)
> std::string just holds a pointer to the actual implementation so
> sizeof(std::string) == sizeof(void*).
> 
> How big is it elsewhere?  It would be interesting to see what this
> program outputs under other compilers:
> 
>     #include <iostream>
>     #include <string>
>     using namespace std;
>     int main() {
> 	string s;
> 	cout << sizeof(s) << endl;
>     }

Some further data points:

Both Intel's (icpc) and HP's (aCC) compilers have
sizeof(std::string) == sizeof(void*) too.

It's 12 with SGI's compiler on mips, and also under Comeau C++ on x86.

And apparently it's 16 in MSVC 6.0:

http://www.thescripts.com/forum/thread164917.html

Be interesting to know what it is for Sun's compiler.

Cheers,
    Olly



More information about the Xapian-devel mailing list