copy on write

  • when a string is created by assignment, the memory is not assigned yet, it uses the existing resource address or pointer
  • when the string is changed, then the memory is assigned
  • this is lazy way
  • example
    std::string x("Hello");
    
    std::string y = x;  // x and y use the same buffer
    
    y += ", World!";    // now y uses a different buffer
                        // x still uses the same old buffer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s