ram内存不足_我的计算机中的RAM可以容纳多少个内存地址?

ram内存不足

ram内存不足

Somedays it’s fun to look at the surface level of the computing experience, and other days it’s fun to delve right into the inner workings. Today we’re taking a look at the structure of computer memory and just how much stuff you can pack into a stick of RAM.

有时候,看一下计算体验的表面层次是很有趣的,而另一些日子,深入研究内部工作是很有趣的。 今天,我们来看看计算机内存的结构,以及可以装进RAM棒中的东西。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

问题 (The Question)

SuperUser reader Johan Smohan is grappling with how processor type and memory size work together to yield a total number of addresses. He writes:

超级用户阅读器Johan Smohan努力解决处理器类型和内存大小如何共同产生地址总数的问题。 他写:

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

32位处理器和1GB内存可以获取多少个内存地址,而64位处理器可以获取多少个内存地址?

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?

1GB的ram除以32位4位(?)以获得内存地址的数量?

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.

我在Wikipedia上读到1个内存地址为32位宽或4个八位位组(1个八位位组= 8位),而64位处理器则为1个内存地址或1个整数为64位宽或8个八位位组。 但是也不知道我是否理解正确。

These are the kinds of questions that can keep a curious geek up at night. How many addresses are available under each of Johan’s hypothetical systems?

这些都是可以使夜间保持好奇的问题。 每个约翰的假设系统下有多少个地址可用?

答案 (The Answer)

SuperUser contributor Gronostaj offers some insight into how the RAM is divided and utilized:

超级用户贡献者Gronostaj提供了有关如何划分和利用RAM的一些见解:

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

简短答案:可用地址的数量等于以下较小者:

  • Memory size in bytes

    内存大小(以字节为单位)
  • Greatest unsigned integer that can be saved in CPU’s machine word

    可以保存在CPU机器字中的最大无符号整数

Long answer and explanation of the above:

以上内容的详细答案和解释:

Memory consists of bytes (B). Each byte consists of 8 bits (b).

内存由字节(B)组成。 每个字节由8位(b)组成。

1 B = 8 b
1 B = 8 b

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

1 GB的RAM实际上是1 GiB(千兆字节,不是千兆字节)。 区别在于:

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.

无论CPU机器字有多大,内存的每个字节都有其自己的地址。 例如。 Intel 8086 CPU是16位的,它按字节寻址内存,现代的32位和64位CPU也是。 这就是第一个限制的原因–您的地址不能超过内存字节。

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.

内存地址只是CPU从内存开头跳到要查找的字节数。

  • To access the first byte it has to skip 0 bytes, so first byte’s address is 0.

    要访问第一个字节,必须跳过0个字节,因此第一个字节的地址为0。
  • To access the second byte it has to skip 1 byte, so its address is 1.

    要访问第二个字节,它必须跳过1个字节,因此其地址为1。
  • (and so forth…)

    (依此类推...)
  • To access the last byte, CPU skips 1073741823 bytes, so its address is 1073741823.

    要访问最后一个字节,CPU会跳过1073741823字节,因此其地址为1073741823。

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

现在,您必须知道32位的实际含义。 如前所述,它是一个机器字的大小。

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 consists of 32 bits.

机器字是CPU用于保存数字(在RAM,高速缓存或内部寄存器中)的内存量。 32位CPU使用32位(4字节)保存数字。 内存地址也是数字,因此在32位CPU上,内存地址由32位组成。

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:

现在考虑一下:如果有一位,则可以在其上保存两个值:0或1。再添加一位,则有四个值:0、1、2、3。在三个位上,可以保存八个值:0,1,2…6,7,7这实际上是一个二进制系统,它的工作方式如下:

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
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.

它的工作原理与通常的加法完全相同,但最大位数为1,而不是9。十进制0为0000 ,然后加1并得到0001 ,再次加一,则得到0010 。 此处发生的情况类似于使用十进制09并加一个:将9更改为0并递增下一位。

From the example above you can see that there’s always a maximum value you can keep in a number with constant 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.

从上面的示例中,您可以看到始终有一个最大值,可以保留位数不变的数字–因为当所有位数均为1并尝试将值增加1时,所有位数都会变为0,从而破坏数。 这称为整数溢出,会给用户和开发人员造成许多不愉快的问题。

11111111    = 255
+         1
-----------
  100000000    = 0   (9 bits here, so 1 is trimmed)
  • For 1 bit the greatest value is 1,

    1位的最大值是1
  • 2 bits – 3,

    2位– 3,
  • 3 bits – 7,

    3位– 7
  • 4 bits – 15

    4位– 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.

可能的最大数目始终为2 ^ N-1,其中N为位数。 如前所述,内存地址是一个数字,并且也有一个最大值。 因此,机器字的大小也限制了可用内存地址的数量–有时您的CPU无法处理足够大的数字以寻址更多的内存。

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.

因此,在32位上,您可以保留从0到2 ^ 32-1的数字,即4 294 967295。它比1 GB RAM中的最大地址还多,因此在特定情况下,RAM的数量将成为限制因素。

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).

理论上32位CPU的RAM限制为4 GB(2 ^ 32),而对于64位CPU,则为16 EB(艾字节,1 EB = 2 ^ 30 GB)。 换句话说,64位CPU可以访问整个Internet…200倍;)(由WolframAlpha估计)。

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.

但是,在实际的操作系统中,32位CPU可以寻址大约3 GiB的RAM。 这是因为操作系统的内部体系结构–一些地址保留用于其他目的。 您可以在Wikipedia上了解有关此所谓的3 GB障碍的更多信息。 您可以使用“ 物理地址扩展”来取消此限制。

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

说到内存寻址,我应该提到的东西很少: 虚拟内存分段分页

Virtual memory

虚拟内存

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

正如@Daniel R Hicks在另一个答案中指出的那样,操作系统使用虚拟内存。 这意味着应用程序实际上不是在实际的内存地址上运行,而是由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 applications more RAM than you actually have installed.

此技术允许操作系统将某些数据从RAM移到所谓的Pagefile(Windows)或Swap(* NIX)中。 HDD比RAM慢几个数量级,但是对于很少访问的数据而言,这并不是一个严重的问题,它使OS为应用程序提供的RAM比实际安装的更多。

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:

想象一下,一本书充满了四个字母的单词。 假设每页上有1024个数字。 要寻址数字,您必须知道两件事:

  • 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.

现在,这正是现代x86 CPU处理内存的方式。 它分为4 KiB页(每页1024个机器字),并且这些页都有数字。 (其实网页也可以是4 MIB大或2 MIB与PAE )。 当您要寻址存储单元时,需要该页中的页码和地址。 请注意,每个存储单元仅由一对数字引用,分段不会如此。

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.

好吧,这与分页非常相似。 仅举一个例子,它用于Intel 8086。 地址组现在称为内存段,而不是页面。 不同之处在于,细分可以重叠,并且确实重叠很多。 例如,在8086上,大多数存储单元可从4096个不同的段中获得。

An example:

一个例子:

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

假设我们有8个字节的内存,除第4个字节等于255外,其余全部为零。

Illustration for flat memory model:

平面内存模型的插图:

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

Illustration for paged memory with 4-byte pages:

具有4字节页面的页面内存的图示

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

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

4字节段移位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  |
                                 -----   -----   -----   -----
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)

如您所见,可以通过四种方式寻址第4个字节:(从0开始寻址)

  • Segment 0, offset 3

    段0,偏移3
  • Segment 1, offset 2

    第1段,偏移2
  • Segment 2, offset 1

    第2段,偏移1
  • Segment 3, offset 0

    段3,偏移量0

It’s always the same memory cell.

它总是相同的存储单元。

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

在实际的实现中,段的偏移量超过1个字节(对于8086,它为16个字节)。

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 smaller than it really is (just small enough to hold the module), then choose first segment that doesn’t overlap with that pseudo-smaller one and load next module, and so on. Basically, what you get this way is pages of variable size.

例如,您可以将某个模块加载到段中,然后假装该段小于实际的段(恰好可以容纳模块),然后选择与该伪较小的段不重叠的第一个段,然后加载模块等等。 基本上,您通过这种方式获得的是可变大小的页面。



Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不对。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/163755/how-many-memory-addresses-can-the-ram-in-my-computer-hold/

ram内存不足

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值