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 9251265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:39:10+00:00 2026-06-18T10:39:10+00:00

I was wondering if there is some way to tell the std::string to release

  • 0

I was wondering if there is some way to tell the std::string to release the char* it is using.

I imagine that somewhere on the std::string it has a field of type char*, I was wanting some method that would to something like that:

const char* std::string::release() {
    const char* result = __str;
    __size = 0;
    __capacity = INITIAL_CAPACITY_WHATEVER;
    __str = new char[INITIAL_CAPACITY_WHATEVER];
    return result;
}

Not that copying the content is a problem or will affect my performance, I just was felling uncomfortable with wasting time copying something that I am just going to delete after.

  • 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-18T10:39:11+00:00Added an answer on June 18, 2026 at 10:39 am

    If you’re using C++11, you can use std::move to move the contents of one string object to another string object. This avoids the overhead of copying.

    std::string s1 = "hello";
    std::string s2(std::move(s1));
    

    However, you cannot directly disassociate the internal char* buffer from an instance of std::string. The std::string object owns the internal char* buffer, and will attempt to deallocate it when the destructor is invoked.

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

Sidebar

Related Questions

I was wondering if there is some way to tell if data was encrypted
I am wondering if there is some way to call C++ code from Common
I am wondering if there is some way to make an box have the
I am wondering if there is some way to replicate Safari (on the iPhone's)
I am wondering if there is some way to rotate a created ABPeoplePickerNavigationController. I
I am wondering if there is some way to do a doesn't equal command
I am wondering if there is some way to fade in and out audio
I am wondering if there is some way to align text on the right
I'm working with a DOMDocument , and I'm wondering if there exists some way
I was wondering if there's a way I could code some kind of generic

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.