You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "Array, strings và slices" section has some wrong concepts/definitions, and also somewhat not clearly, since when it introduces strings before slices. The official Go blog has an introduction post about "Arrays, slices (and strings)".
type StringHeader struct {
// con trỏ địa chỉ vùng nhớ string
Data uintptr
// chiều dài của string
Len int
}
This is wrong, Data is an uintptr (Numeric types), not a pointer type, even though its value is the pointer address in memory. This is important concept, otherwise, it can lead to wrong assumption and cause memory corruption. The official Go documentation has a warning for this.
The same problem applies to the slices section:
Data: là con trỏ chứa địa chỉ của một array.
Wrong description about len builtin
Tương tự như array, String cũng có một hàm built-in là len dùng để trả về chiều dài của string
len is not a function of String, it's a builtin function, which can take various types of argument, including string type.
Wrong word about ranging over slice
Duyệt qua slice thì tương tự như duyệt qua một arrays.
This is not true. Ranging over an array requires copying the array elements, while ranging over slice is not (the same as ranging over pointer to array).
The description of slice growing capacity is not quite right
Trong trường hợp slice ban đầu không đủ sức chứa khi thêm vào phần tử, hàm append sẽ hiện thực cấp phát lại vùng nhớ có kích thước gấp đôi vùng nhớ cũ và sao chép dữ liệu sang.
This is only right for slice with < 1024 element, for slice with >= 1024 element, the grow factor is only 1.25 (and the factor can be smoother in go1.18, see https://go-review.googlesource.com/c/go/+/347917)
Expected behavior
Re-organizing the section to follow official Go blog, and also correct all the wrong definition.
The text was updated successfully, but these errors were encountered:
hi @cuonglm,
Thanks for your feedback. I have reviewed and corrected the issues you mentioned. I created a PR here to fix it.
In the future, we very happy if you can contribute to this project to make this project better for the community.
Describe the bug
The "Array, strings và slices" section has some wrong concepts/definitions, and also somewhat not clearly, since when it introduces strings before slices. The official Go blog has an introduction post about "Arrays, slices (and strings)".
To Reproduce
At revision e19da2e:
uintptr
This is wrong,
Data
is anuintptr
(Numeric types), not a pointer type, even though its value is the pointer address in memory. This is important concept, otherwise, it can lead to wrong assumption and cause memory corruption. The official Go documentation has a warning for this.The same problem applies to the slices section:
len
builtinlen is not a function of String, it's a builtin function, which can take various types of argument, including
string
type.This is not true. Ranging over an array requires copying the array elements, while ranging over slice is not (the same as ranging over pointer to array).
This is only right for slice with < 1024 element, for slice with >= 1024 element, the grow factor is only 1.25 (and the factor can be smoother in go1.18, see https://go-review.googlesource.com/c/go/+/347917)
Expected behavior
Re-organizing the section to follow official Go blog, and also correct all the wrong definition.
The text was updated successfully, but these errors were encountered: