This question already has an answer here:
- Why is sizeof(string) == 32? 6 answers
- Why is sizeof(std::string) only eight bytes? 2 answers
Consider following program:
#include <iostream>
#include <string>
int main() {
std::cout << sizeof(std::string);
}
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