时间内访问任何内存地址

时间内访问任何内存地址

本文介绍了为什么 RAM 在 O(1) 时间内访问任何内存地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我们处理数组时,赋值 a[10000] = 3,它的作用是先将 10000 * sizeof(int) 添加到 a 的内存地址,然后访问该内存地址.问题是,为什么访问这样的内存地址只需要 O(1) 时间?基本上,随机存取存储器背后的魔力是什么,使得访问地址#1 和地址#1,000,000 需要相同的时间?

When we work with arrays, for example, assign a[10000] = 3, what it does is it first add 10000 * sizeof(int) to memory address of a, and then access that memory address. The question is, why does accessing such memory address takes only O(1) time? Basically, what's the magic behind random access memory such that it takes the same time accessing address #1 vs. address #1,000,000?

推荐答案

随机存取存储器顾名思义就是可以在一定时间内提供任何地址的内容的存储器.这就是随机访问"位,以及它与其他类型内存的区别.

Random access memory is by definition memory that can provide the contents at any address in a constant amount of time. That's the 'random access' bit, and what distinguishes it from other types of memory.

不涉及魔法;只有 n 个位置,访问内存的人会提供详细信息以选择其中之一.

There's no magic involved; there are just n locations, and whomever is accessing memory provides the details to select one of them.

在大多数实现中,内存中的每个字都是相同的电子元件.您只是选择连接到总线的那个.

In most implementations every word of memory is an identical piece of electronics. You're just selecting which is connected to the bus.

这篇关于为什么 RAM 在 O(1) 时间内访问任何内存地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:33