N
Nephi Immortal
string class has four data members: proxy class, buffer, size, and capacity.. The buffer has fixed 16 elements. It is stored into stack. If you insert between 1 and 16 characters into string’s buffer, the buffer with fixed 16 elements is filled. If you insert more than 16 characters, 4 elementsout of 16 elements in the buffer is replaced with pointer to char or char*before new buffer is allocated into heap.
What happen if you delete all the characters or leave one character in the buffer? The buffer in the heap will be reallocated to 32 elements in heap or deallocated before memory address in the buffer with fixed 16 elements will be overwritten to store between 1 and 16 characters.
The basic_string source code of Microsoft looks weird and is so confusing. Do advanced programmers read and understand it?
Reminder: overwritten buffer may be possible to overwrite other data members in memory. It is considered unsafe. I have seen across several websites.. Some programmers don't like Microsoft's code so that they write their own string class.
What happen if you delete all the characters or leave one character in the buffer? The buffer in the heap will be reallocated to 32 elements in heap or deallocated before memory address in the buffer with fixed 16 elements will be overwritten to store between 1 and 16 characters.
The basic_string source code of Microsoft looks weird and is so confusing. Do advanced programmers read and understand it?
Reminder: overwritten buffer may be possible to overwrite other data members in memory. It is considered unsafe. I have seen across several websites.. Some programmers don't like Microsoft's code so that they write their own string class.