Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:52:23+00:00 2026-06-04T17:52:23+00:00

When writing a C++ application, I normally limit myself to C++ specific language features.

  • 0

When writing a C++ application, I normally limit myself to C++ specific language features. Mostly this means using STL instead of CRT where ever possible.

To me, STL is just so much more fluid and maintainable than using CRT. Consider the following:

std::string str( "Hello" );
if( str == "Hello" ) { ... }

The C-Runtime equivalent would be:

char const* str = "Hello";
if( strcmp( str, "Hello" ) == 0 ) { ... }

Personally I find the former example much easier to look at. It’s just more clear to me what’s going on. When I write a first pass of my code, the first thing on my mine is always to write code in the most natural way.

One concern my team has with the former example is the dynamic allocation. If the string is static OR has already been allocated elsewhere, they argue it doesn’t make sense to potentially cause fragmentation or have a wasteful allocation here. My argument against this is to write code in the most natural way first, and then go back and change it after getting proof that the code causes a problem.

Another reason I don’t like the latter example is that it uses the C Library. Typically I avoid it at all costs simply because it’s not C++, it’s less readable, and more error prone and is more of a security risk.

So my question is, am I right to avoid it the C Runtime? Should I really care about the extra allocation at this step in coding? It’s hard for me to tell if I’m right or wrong in this scenario.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:52:25+00:00Added an answer on June 4, 2026 at 5:52 pm

    I feel like my comment about llvm::StringRef went ignored, so I’ll make an answer out of it.

    llvm::StringRef str("Hello");
    

    This essentially sets a pointer, calls strlen, then sets another pointer. No allocation.

    if (str == "Hello") { do_something(); }
    

    Readable, and still no allocation. It also works with std::string.

    std::string str("Hello");
    llvm::StringRef stref(str);
    

    You have to be careful with that though, because if the string is destroyed or re-allocated, the StringRef becomes invalid.

    if (str == stref) { do_something(); }
    

    I have noticed quite substantial performance benefits when using this class in appropriate places. It’s a powerful tool, you just need to be careful with it. I find that it is most useful with string literals, since they are guaranteed to last for the lifetime of the program. Another cool feature is that you can get substrings without creating a new string.

    As an aside, there is a proposal to add a class similar to this to the standard library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Desktop GUI application in Clojure using Java Swing. Normally when
I am writing an application in java (1.6) using swing. I currently have a
It started quite normally. I'm writing complex calculation application for iPhone. I decided to
I am writing a WPF application using Self-Tracking Entities. I'm having trouble Disabling/Enabling my
I'm writing a Django application that is using pip & virtualenv to manage its
Im writing an application that supposed to send coordinates in an SMS, but I've
When writing an application to support scalability, how do I decide whether to support
I'm writing an application and I'm able to set its throughput (the number of
I am writing Windows application (with Borland C++ Builder), which stores large number of
I'm writing an application that will create difficult passwords for the user. The user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.