Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

翻转字符串 #19

Open
butalso opened this issue Jul 28, 2020 · 6 comments
Open

翻转字符串 #19

butalso opened this issue Jul 28, 2020 · 6 comments

Comments

@butalso
Copy link

butalso commented Jul 28, 2020

这个题目,不发生内存拷贝?? 讲道理, 字符串数组转换成[]rune切片, 就已经发生了内存拷贝了好吧

@baronwithyou
Copy link
Contributor

baronwithyou commented Aug 10, 2020

@butalso

这个题目,不发生内存拷贝?? 讲道理, 字符串数组转换成[]rune切片, 就已经发生了内存拷贝了好吧

切片是在原有数组上进行操作的,而字符串本质上是一个字节数组,因而不会再开辟一块新的内存空间。

详情请翻阅:https://learnku.com/docs/the-way-to-go/the-application-of-76-strings-arrays-and-slices/3617

@butalso
Copy link
Author

butalso commented Aug 12, 2020

字符串是不可修改的, 字节数组是可以修改的,不会开辟一块新内存??那字节数组改了, 字符串会变吗?

@mlixytz
Copy link

mlixytz commented Sep 23, 2020

@butalso

这个题目,不发生内存拷贝?? 讲道理, 字符串数组转换成[]rune切片, 就已经发生了内存拷贝了好吧

切片是在原有数组上进行操作的,而字符串本质上是一个字节数组,因而不会再开辟一块新的内存空间。

详情请翻阅:https://learnku.com/docs/the-way-to-go/the-application-of-76-strings-arrays-and-slices/3617

字节数组转换为字符串,字符串转换为字节数组都会发生内存copy。具体查看这里:类型转换

@butalso
Copy link
Author

butalso commented Sep 28, 2020

所以, 这个题目看起来不是很靠谱吧

@yutianyong125
Copy link

错别字好像有点多

@luliangce
Copy link

前两个算法题的答案看起来都很不靠谱,当然也可能是题目没说清楚。
string作为不可变类型,切片之后肯定是拷贝的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants