Giter VIP home page Giter VIP logo

Comments (6)

mlixytz avatar mlixytz commented on May 17, 2024 1

@butalso

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

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

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

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

from interview-go.

baronwithyou avatar baronwithyou commented on May 17, 2024

@butalso

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

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

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

from interview-go.

butalso avatar butalso commented on May 17, 2024

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

from interview-go.

butalso avatar butalso commented on May 17, 2024

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

from interview-go.

yutianyong125 avatar yutianyong125 commented on May 17, 2024

错别字好像有点多

from interview-go.

luliangce avatar luliangce commented on May 17, 2024

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

from interview-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.