dimanche 23 juillet 2017

sizeof(std::string) in C++ [duplicate]

This question already has an answer here:

Consider following program:

#include <iostream>
#include <string>
int main() {
    std::cout << sizeof(std::string);
}

See live demo here & here

g++ 4.8.1 gives 8 as an output. But g++ 7.1.0 gives 32 as output. Why sizeof(std::string) has become 4x times larger now ? Isn't it nice to have an implementation where std::string occupies less space? Isn't this behaviour unusual ?

Aucun commentaire:

Enregistrer un commentaire