我的计算机中的ram能容纳多少个内存地址?

有时,看一看表面的计算体验是很有趣的,而另一些时候,深入研究内部工作是很有趣的。今天我们来看看计算机内存的结构,以及你能把多少东西装进一个RAM中。...

我的计算机中的ram能容纳多少个内存地址?

有时,看一看表面的计算体验是很有趣的,而另一些时候,深入研究内部工作是很有趣的。今天我们来看看计算机内存的结构,以及你能把多少东西装进一个RAM中。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户阅读器johan**ohan正在努力研究处理器类型和内存大小如何协同工作以产生地址总数。他写道:

How many memory addresses can we get with a 32-bit processor and 1GB ram and how many with a 64-bit processor?

I think that it’s something like this:

1GB of ram divided by either 32 bits  4  bits (?) to get the number of memory addresses?

I read on Wikipedia that 1 memory addresses is 32 bits wide or 4 octets (1 octet = 8 bits), compared to a 64 bit processor where 1 memory addresses or 1 integer is 64 bits wide or 8 octets. But don’t know if I understood it correctly either.

这些问题可以让一个好奇的极客在晚上睡不着觉。Johan假设的每个系统下有多少个地址?

答案

SuperUser contributor Gronostaj提供了一些关于RAM如何分配和利用的见解:

Short answer: The number of available addresses is equal to the **aller of those:

  • Memory size in bytes
  • Greatest unsigned integer that can be saved in CPU’s machine word

Long answer and explanation of the above:

Memory c***ists of bytes (B). Each byte c***ists of 8 bits (b).

1 B = 8 b

1 GB of RAM is actually 1 GiB (gibibyte, not gigabyte). The difference is:

1 GB = 10^9 B = 1 000 000 000 B 1 GiB = 2^30 B = 1 073 741 824 B

Every byte of memory has its own address, no matter how big the CPU machine word is. Eg. Intel 8086 CPU was 16-bit and it was addressing memory by bytes, so do modern 32-bit and 64-bit CPUs. That’s the cause of the first limit – you can’t have more addresses than memory bytes.

Memory address is just a number of bytes the CPU has to skip from the beginning of the memory to get to the one it’s looking for.

  • To access the first byte it has to skip 0 bytes, so first byte’s address is 0.
  • To access the second byte it has to skip 1 byte, so its address is 1.
  • (and so forth…)
  • To access the last byte, CPU skips 1073741823 bytes, so its address is 1073741823.

Now you have to know what 32-bit actually means. As I mentioned before, it’s the size of a machine word.

Machine word is the amount of memory CPU uses to hold numbers (in RAM, cache or internal registers). 32-bit CPU uses 32 bits (4 bytes) to hold numbers. Memory addresses are numbers too, so on a 32-bit CPU the memory address c***ists of 32 bits.

Now think about this: if you have one bit, you can save two values on it: 0 or 1. Add one more bit and you have four values: 0, 1, 2, 3. On three bits, you can save eight values: 0, 1, 2… 6, 7. This is actually a binary system and it works like that:

Binary Decimal 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

It works exactly like usual addition, but the maximum digit is 1, not 9. Decimal 0 is 0000, then you add 1 and get 0001, add one once again and you have 0010. What happend here is like with having decimal 09 and adding one: you change 9 to 0 and increment next digit.

From the example above you can see that there’s always a maximum value you can keep in a number with c***tant number of bits – because when all bits are 1 and you try to increase the value by 1, all bits will become 0, thus breaking the number. It’s called integer overflow and causes many unpleasant problems, both for users and developers.

11111111 = 255 + 1 ----------- 100000000 = 0 (9 bits here, so 1 is trimmed)
  • For 1 bit the greatest value is 1,
  • 2 bits – 3,
  • 3 bits – 7,
  • 4 bits – 15

The greatest possible number is always 2^N-1, where N is the number of bits. As I said before, a memory address is a number and it also has a maximum value. That’s why machine word’s size is also a limit for the number of available memory addresses – sometimes your CPU just can’t process numbers big enough to address more memory.

So on 32 bits you can keep numbers from 0 to 2^32-1, and that’s 4 294 967 295. It’s more than the greatest address in 1 GB RAM, so in your specific case amount of RAM will be the limiting factor.

The RAM limit for 32-bit CPU is theoretically 4 GB (2^32) and for 64-bit CPU it’s 16 EB (exabytes, 1 EB = 2^30 GB). In other words, 64-bit CPU could address entire Internet… 200 times ;) (estimated byWolframAlpha).

However, in real-life operating systems 32-bit CPUs can address about 3 GiB of RAM. That’s because of operating system’s internal architecture – some addresses are reserved for other purposes. You can read more about this so-called 3 GB barrier on Wikipedia. You can lift this limit with Physical Address Extension.

Speaking about memory addressing, there are few things I should mention: virtual memory, segmentation and paging.

Virtual memory

As @Daniel R Hicks pointed out in another answer, OSes use virtual memory. What it means is that applicati*** actually don’t operate on real memory addresses, but ones provided by OS.

This technique allows operating system to move some data from RAM to a so-called Pagefile (Windows) or Swap (*NIX). HDD is few magnitudes slower than RAM, but it’s not a serious problem for rarely accessed data and it allows OS to provide applicati*** more RAM than you actually have installed.

Paging

What we were talking about so far is called flat addressing scheme.

Paging is an alternative addressing scheme that allows to address more memory that you normally could with one machine word in flat model.

Imagine a book filled with 4-letter words. Let’s say there are 1024 numbers on each page. To address a number, you have to know two things:

  • The number of page on which that word is printed.
  • Which word on that page is the one you’re looking for.

Now that’s exactly how modern x86 CPUs handle memory. It’s divided into 4 KiB pages (1024 machine words each) and those pages have numbers. (actually pages can also be 4 MiB big or 2 MiB with PAE). When you want to address memory cell, you need the page number and address in that page. Note that each memory cell is referenced by exactly one pair of numbers, that won’t be the case for segmentation.

Segmentation

Well, this one is quite similar to paging. It was used in Intel 8086, just to name one example. Groups of addresses are now called memory segments, not pages. The difference is segments can overlap, and they do overlap a lot. For example on 8086 most memory cells were available from 4096 different segments.

An example:

Let’s say we have 8 bytes of memory, all holding zeros except for 4th byte which is equal to 255.

Illustration for flat memory model:

_____ | 0 | | 0 | | 0 | | 255 | | 0 | | 0 | | 0 | | 0 | -----

Illustration for paged memory with 4-byte pages:

PAGE0 _____ | 0 | | 0 | | 0 | PAGE1 | 255 | _____ ----- | 0 | | 0 | | 0 | | 0 | -----

Illustration for segmented memory with 4-byte segments shifted by 1:

SEG 0 _____ SEG 1 | 0 | _____ SEG 2 | 0 | | 0 | _____ SEG 3 | 0 | | 0 | | 0 | _____ SEG 4 | 255 | | 255 | | 255 | | 255 | _____ SEG 5 ----- | 0 | | 0 | | 0 | | 0 | _____ SEG 6 ----- | 0 | | 0 | | 0 | | 0 | _____ SEG 7 ----- | 0 | | 0 | | 0 | | 0 | _____ ----- | 0 | | 0 | | 0 | | 0 | ----- ----- ----- -----

As you can see, 4th byte can be addressed in four ways: (addressing from 0)

  • Segment 0, offset 3
  • Segment 1, offset 2
  • Segment 2, offset 1
  • Segment 3, offset 0

It’s always the same memory cell.

In real-life implementati*** segments are shifted by more than 1 byte (for 8086 it was 16 bytes).

What’s bad about segmentation is that it’s complicated (but I think you already know that ;) What’s good, is that you can use some clever techniques to create modular programs.

For example, you can load some module into a segment, then pretend the segment is **aller than it really is (just **all enough to hold the module), then choose first segment that doesn’t overlap with that pseudo-**aller one and load next module, and so on. Basically, what you get this way is pages of variable size.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

 

 

 

  • 发表于 2021-04-11 18:59
  • 阅读 ( 230 )
  • 分类:互联网

你可能感兴趣的文章

高速缓存(cache memory)和虚拟内存(virtual memory)的区别

...中。因此,下一次发生缓存命中的概率很高,因为大多数计算机程序都会访问附近的数据或上次访问的数据。因此,由于缓存,平均内存延迟减少了。 在CPU中,有三种类型的缓存:用于存储程序指令的指令缓存、用于存储数据...

  • 发布于 2020-10-29 11:12
  • 阅读 ( 864 )

更快的内存与更多的内存:哪一个对性能更重要?

围绕这些部件,我们鼓励您升级现有的计算机,而不是购买新的。它更容易放在你的钱包里,有助于减少电子垃圾的数量。但正如通常情况一样,存钱需要一点知识。 ...

  • 发布于 2021-03-15 01:24
  • 阅读 ( 166 )

为什么googlechrome使用了这么多内存?下面是如何修复它

... 计算机上的每个应用程序都在计算机的RAM中运行进程,在RAM中运行计算机是一项艰巨的工作。RAM是存储各种数据的临时存储器,速度非常快。CPU访问系统RAM中的数据的速度...

  • 发布于 2021-03-18 04:16
  • 阅读 ( 324 )

ram对游戏有什么作用?我需要多少ram?

...PC时,您需要考虑几个组件。每一项都以不同的方式影响计算机的性能,忽略任何一项都可能导致瓶颈。 ...

  • 发布于 2021-03-20 05:14
  • 阅读 ( 791 )

如何查看chromebook中有多少ram

当谈到计算机运行的好坏时,RAM是很重要的。Chromebook比运行Windows 10或macOS的其他计算机需要更少的RAM。不过,你可能觉得你需要更多。我们将向您展示如何了解您的Chromebook有多少RAM。 如果你碰巧知道你的Chromebook型号,你可以...

  • 发布于 2021-03-31 20:35
  • 阅读 ( 149 )

“统一内存”如何加速苹果m1 arm Mac

...也出现在Mac上,这是一种为更重的工作负载而设计的成熟计算机。 相关报道:苹果用于Mac的M1芯片是什么? 什么是ram和内存(ram and memory)? RAM代表随机存取存储器。它是系统内存的主要组成部分,系统内存是一个临时存储空间...

  • 发布于 2021-04-01 01:26
  • 阅读 ( 370 )

如何在linux上使用free命令

Linux free命令显示您的计算机有多少内存正在使用,还有多少内存可供程序使用。它的输出可能会让新手感到困惑,但我们将向您展示如何理解它。 自由命令 free命令在终端窗口中打印内存使用情况的快速摘要。它没有太多的选...

  • 发布于 2021-04-02 19:12
  • 阅读 ( 174 )

为什么你应该超频你的内存(很容易!)

...的指南,超频你的内存来了解更多。相关:如何超频您的计算机的RAM?

  • 发布于 2021-04-03 04:08
  • 阅读 ( 157 )

如何查看您的pc中有多少ram(及其速度)

计算机的RAM是它用来运行应用程序和打开文件的快速短期内存。你的计算机内存越多,你一次能做的事情就越多。下面是如何检查你的系统有多少。 我们还将向您展示如何检查RAM的速度。就像几乎所有的技术一样,除了电池,RA...

  • 发布于 2021-04-03 06:52
  • 阅读 ( 277 )

如何升级或更换电脑的ram

...的电脑能处理多少内存? RAM等式的另一部分是知道你的计算机能支持多少RAM。这里有两个因素:您的Windows版本可以处理的最大RAM,以及您的主板可以处理的最大RAM。不管是什么低是你坚持的,但它是典型的主板,这是更大的限...

  • 发布于 2021-04-06 11:51
  • 阅读 ( 367 )
阿鑫鑫吖
阿鑫鑫吖

0 篇文章

相关推荐