Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++RAD Studio

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?

  • string_view lives in the <string_view> header file

Benefits of the string_view

  • string_view is useful when you want to avoid unnecessary duplicates
  • The creation of string_view from literals does not need a dynamic allocation.

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

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.

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


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Software Developer | B.Tech-CSE at AUT | Delphi/C++ Builder Enthusiast | Microsoft Learn Student Ambassador | Microsoft Azure Certified | Udacity Alumni
Related posts
CodeDatabaseDelphiRAD Studio

Quickly Learn How Easy It Is To Bind DataSets To Visual Controls In Delphi With LiveBindings

C++CodeRAD Studio

Learn How To Use C++ Incomplete Return Types In Windows Development

C++Delphi

Create Beautiful Windows Applications With Visually Stunning VCL Styles For Delphi And C++

CodeDelphiRAD Studio

Master A Powerful Way To Execute Multiple SQL Commands In Delphi With This Windows Sample

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES