我的計算機中的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
  • 閱讀 ( 55 )
  • 分類:網際網路

你可能感興趣的文章

猛撞(ram)和只讀儲存器(rom)的區別

...的速度非常快。考慮一臺需要加上使用者輸入的兩個數字的計算機。當用戶輸入這兩個數字時,計算機將這些數字儲存在RAM中。之後,它將結果儲存在RAM中供使用者讀取。這就是計算機或微處理器在RAM中讀寫資料的方式。同樣,...

  • 發佈於 2020-10-16 15:33
  • 閲讀 ( 71 )

更快的記憶體與更多的記憶體:哪一個對效能更重要?

圍繞這些部件,我們鼓勵您升級現有的計算機,而不是購買新的。它更容易放在你的錢包裡,有助於減少電子垃圾的數量。但正如通常情況一樣,存錢需要一點知識。 ...

  • 發佈於 2021-03-15 01:24
  • 閲讀 ( 43 )

程式設計師指標簡介

... 要完成此任務,您的計算機將訪問其保留的記憶體位置,並將其中儲存的任何值更改為新值。 ...

  • 發佈於 2021-03-15 04:42
  • 閲讀 ( 42 )

如何升級mac上的ram

...,看看Critical的Mac記憶體集線器。在這裡,您可以輸入您的計算機資訊(找到之前)或下載一個掃描工具,為您檢查。然後您將看到一個包含ssd和RAM的頁面,它們保證在您的機器中工作。 ...

  • 發佈於 2021-03-20 01:17
  • 閲讀 ( 55 )

ram對遊戲有什麼作用?我需要多少ram?

...防您對RAM一點都不熟悉,讓我們簡單地定義一下這個重要的計算機元件的功能。有關更多資訊,請參閱我們的RAM簡介。 ...

  • 發佈於 2021-03-20 05:14
  • 閲讀 ( 44 )

“統一記憶體”如何加速蘋果m1 arm Mac

...公羊?當我們談論Windows pc時,一般的建議是8GB對於基本的計算任務已經足夠了。遊戲玩家最好把這個數字提高到16GB,而“prosumer”的活動可能需要加倍才能完成編輯大型高解析度影片檔案等任務。 同樣,對於m1mac,8GB的基本型...

  • 發佈於 2021-04-01 01:26
  • 閲讀 ( 52 )

如何在linux上使用free命令

Linux free命令顯示您的計算機有多少記憶體正在使用,還有多少記憶體可供程式使用。它的輸出可能會讓新手感到困惑,但我們將向您展示如何理解它。 自由命令 free命令在終端視窗中列印記憶體使用情況的快速摘要。它沒有太...

  • 發佈於 2021-04-02 19:12
  • 閲讀 ( 47 )

linux上的交換是什麼?(以及如何更改)

...為什麼? 這取決於硬體、工作負載、硬碟型別,以及您的計算機是桌上型電腦還是伺服器。顯然,這不會是一個一刀切的設定型別。 您必須記住,當記憶體空間耗盡時,swap不僅僅是一種釋放RAM的機制。Swap是一個功能良好的系...

  • 發佈於 2021-04-02 20:43
  • 閲讀 ( 52 )

如何超頻您的計算機的ram

...,其餘的由主機板決定,這並不總是做出正確的選擇。在我的例子中,我的華碩主機板的“自動”設定為一些計時設定了一些奇怪的值。我的RAM套件拒絕執行XMP配置檔案,直到我自己修復了計時。 如何確定最佳ram計時 雖然超頻...

  • 發佈於 2021-04-03 04:44
  • 閲讀 ( 47 )

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

...,直到你調整時間。 相關:記憶體速度和時間如何影響我的電腦的效能? 此資訊通常也顯示在系統的UEFI韌體或BIOS中。如果您使用的電腦沒有正常工作的作業系統,這一點尤其有用。只需啟動它,使用鍵盤快捷鍵輸入它的BIOS或...

  • 發佈於 2021-04-03 06:52
  • 閲讀 ( 39 )
阿鑫鑫吖
阿鑫鑫吖

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦