Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Achieve High Performance By Using The string_view C++17 Feature In C++Builder

achieve high performance by using c17 feature string viev

In this tutorial, you will learn another modern C++17 feature to work with strings. This feature is a std::string_view. The purpose of any kinds of string reference proposals is to bypass copying data that already owned someplace and of which only a non-mutating representation is required. The std::string_view is one such proposal. There was an earlier one named string_ref.

The std::string_view is a picture of the string and cannot​ be utilized to alter the original string value. When a std::string_view is constructed, there’s no need to replicate the data. Besides, the std::string_view is smaller than std::string on the heap.

How can you use std::string_view with C++ Builder?

Benefits of the string_view

The following code illustrates how string_view supports save memory by restricting unnecessary dynamic allocations:

[crayon-674296ff89c95127666400/]

So, std::string_view is an extraordinary utility for great performance. But, the programmer must assure that std::string_view does not outlive the pointed-to character array.

Additional functions provided by std::string_view can be found here, on the official documentation.

Check out everything you need to know about Substring C++ in this informative blog.

Head over and check out the Windows string_view demo for C++Builder on GitHub.

Exit mobile version