Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QString str_a("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
- qDebug() << str_a.constData(); // print out address of data buffer
- // With copy-on-write strings, str_b does not yet allocate a new buffer and copy str_a's content into it. An associated reference counter for the data is increased instead.
- QString str_b=str_a;
- qDebug() << str_b.constData(); // print out address of data buffer, it is the same as for str_a
- // str_a notices that the reference counter to its current shared data is >1, therefore it can't copy assign "Quisque..." directly into the buffer. Rather a new memory buffer is allocated, the new text copied there and the reference count to the "Lorem ipsum..."-string is decreased by one.
- str_a="Quisque mollis elit sed vehicula luctus.";
- qDebug() << str_a.constData(); // now a new address
- qDebug() << str_b.constData(); // same as for the initial printout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement