Why Redis To achieve a SDS yourself

Redis is using C language development, there is no such data type string, string, mostly through an array of characters implemented in the C language, but use an array of characters has the following shortcomings:

1. The length of the character array are fixed, a null pointer prone
2 to get the length of the character array when the array need convenience, time complexity is high
reallocate 3. The length character array is changed after the memory
4. \ 0 represents the end, the problem will occur when storing binary.


Redis so on their own to achieve the SDS solve the above problems, the following are some of the advantages of relatively SDS:
1. have a length corresponding to a certain standard expansion. So as to solve the problem of memory overflow.
2. SDS defines the inside length of the string, can directly use. So as to solve the issue of access and high complexity length of time.
3. SDS space is pre-allocated, an inert free memory. Thereby reducing the number of allocated memory
4. SDS determined according to the length of the end position. So as to solve the problem of binary unsafe.

Guess you like

Origin www.cnblogs.com/excellencesy/p/11684549.html
Recommended