The sequential storage structure of strings uses a set of sequential storage units to store character sequences in strings. Assign a fixed-length storage area for each defined string variable according to the predefined size. It is generally defined by a fixed-length array.
Since it is a fixed-length array, there is a predefined maximum String Length. Generally, the actual String Length value can be saved at the 0 subscript position of the array, some books also define the position of the last subscript stored in the array.
- However, some programming languages do not want to do this, and it is troublesome to store numbers. It requires that an end tag character not included in the length of the string be added after the string value, such as "\ o" to indicate the end of the string value. At this time, you need to know the length of the string at this time, you only need to traverse and compute to find out. In fact, this still takes up a space. Haowangbo entertainment city
The sequential storage method of strings mentioned earlier is actually problematic, because string operations, such as the connection Concat of two strings, the insertion of strlnsert of new strings, and the replacement of replace of strings, it is possible that the length of the string sequence exceeds the length of the array maxsize.
- That is to say, the disadvantage of the sequential string storage structure is the string truncation. truncation means that the string value exceeding the predefined length is removed.
As a result, there are some changes to the sequential storage of strings. The storage space of string values can be dynamically allocated during program execution. For example, a free storage zone in a computer is called a heap ". This heap can be managed by the dynamic allocation functions malloc () and free () in C language.
Next, we try to implement the string data structure according to the operation defined by the string ADT.
How to store strings in memory?