本文介绍了C ++ 11内部std ::字符串表示(libstdc ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c ++ 11(libstdc ++)中内部表示std :: string?

How std::string is internally represented in c++11 (libstdc++)?

在实现过程中,我发现:

While digging inside the implementation, I found:

 c>继承 _Rep_Base  

std::string doesn't have a _Rep_Base member but a pointer to _Rep with _Rep inheriting from _Rep_Base

这里解释的是:

 *  Where the _M_p points to the first character in the string, and
 *  you cast it to a pointer-to-_Rep and subtract 1 to get a
 *  pointer to the header.



缓冲区位于标题...之后



是的,但是在_Rep对象的头之后,你的字符串只有一个指向它的指针。

The buffer lies after the header...

Yes, but after the header of the _Rep object, and your string only has a pointer to it.

这篇关于C ++ 11内部std ::字符串表示(libstdc ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:12