Giter VIP home page Giter VIP logo

Comments (3)

Talent-Rain avatar Talent-Rain commented on May 27, 2024 2
  • 对于 JS 而言,数组变量其实就是一个指针,而数组的索引值表示偏移量的个数;
  • 好像设计数组的时候,每个值的类型都是一样的,所以每一个存缓存的内存也是一样的,一个值所占的内存大小就是一个偏移量的大小;
  • 所以对于数组的第一个值,就是指针所在的位置,偏移量为0;对于第二个值,就是偏移了第一个值的位置,所以是 start + 1 * 偏移量;
  • 这样当我们用索引来求数组索引值为 N 的值的时候,给的是 arr[n] , 计算机到 start+n*K 就能找到所在位置了;如果以 1 开始,那么每次查找就要多处理一次 n-1 的操作 start+(n-1)*K
  • 以上是一个小前端看了之前的书了解的,谢谢

from fe-interview.

azl397985856 avatar azl397985856 commented on May 27, 2024
  1. 索引的含义是偏移量(offset),偏移量从 0 开始,因此索引也从 0 开始。
  2. 数组需要支持随机访问,一种实现方式就是通过 基值+偏移量*每项的字节数 访问任意索引位置。如果索引从 1 开始,那么偏移量就等于索引-1,这样会多一次减法运算。

from fe-interview.

stale avatar stale commented on May 27, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from fe-interview.

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.