Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is GCC's "vstring"?

Tags:

I read some GCC bugreport and people there were talking about "vstring". Searching the WEB I came to notice http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/vstring_8h.html .

Can someone please elaborate on what it is useful and used for? Why use it instead of std::string?

like image 738
Johannes Schaub - litb Avatar asked May 05 '12 16:05

Johannes Schaub - litb


People also ask

What is the difference between GCC-s and strip?

gcc -s: Remove all symbol table and relocation information from the executable. strip: Discard symbols from object files. Do they have the same meaning? reduce the size of executable? speed up its running? Show activity on this post. gcc being a compiler/linker, its -s option is something done while linking.

What are the different options of GCC command?

The different options of gcc command allow the user to stop the compilation process at different stages. Syntax: gcc [-c|-S|-E] [-std=standard] Example: This will compile the source.c file and give the output file as a.out file which is default name of output file given by gcc compiler, which can be executed using ./a.out gcc source.c

What is the use of GCC in C++?

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The most important option required while compiling a source code file is the name of the source program, rest every argument is optional like a warning, debugging, linking libraries, object ...

What is the difference between a string and a V_String?

Essentially, string is the most limited type and has a length that does not vary much and only contains simple Latin-1 characters. V_string also contains simple Latin-1 characters but can have a varying length.


1 Answers

GCC's vstring is a versatile string class, which was introduced in GCC 4.1's libstdc++ implementation.

It is compatible with std::basic_string, with these additional details:

  • Two base classes are provided:
    • the default one avoids reference counting and is optimized for short strings;
    • the alternate one, still uses it (reference counting, that is) while improving in a few low level areas (e.g., alignment). See vstring_fwd.h for some useful typedefs.
  • Various algorithms have been rewritten (e.g., replace), the code streamlined and simple optimizations added.
  • Option 3 of DR 431 is implemented for both available bases, thus improving the support for stateful allocators.

DR431 is Library Working Group Defect Report 431, with option 3 looking like implementing better allocator support for the class to allow better swapping and other allocator-related operations.

The basic details are from GCC 4.1's release notes, under the Runtime Library section.

edit:

It looks as though the original purpose of this extension was to provide a basis for a C++11 std::string implementation. Paolo Carlini, a GCC/libstdc++ contributor, comments in this GCC Bug Report that <ext/vstring.h> contains a non-reference counted experimental version of the next std::string. Comment dated April 12, 2012:

What we tried to explain is that this sort of issue is well known and, more or less, affects any reference counted implementation... That is not the case when reference counting is not used and indeed it will not be used (per the new C++11 Standard) in a new implementation of std::string which we are currently showcasing as <ext/vstring.h>...

like image 181
逆さま Avatar answered Sep 23 '22 05:09

逆さま