跟讀練習: You are wasting memory - 通過影片學習英語口語
選擇練習模式
每種模式都會開啟全屏練習室。
27 句
如果句子過短或過長,請點選 Edit 進行調整。
1
Take a look at this C code and tell me what the output of that printf will be.
2
If you said 12, you are correct, and that's because each integer is 4 bytes wide.
3
Now, what happens if I add a character to the structure?
4
You probably already know that a character has a size of 1 byte, but if we run this program, we can see that the structure became 16 bytes.
5
This happens because of memory alignment.
6
You can imagine memory as a row of numbered boxes, where each number represents an address.
7
Each box can hold exactly one byte.
8
We know that on 64-bit machines an integer is usually four bytes.
9
For it to be aligned, its address must be a multiple of its size.
10
If a value is not aligned, on some architectures and older computers, working with it might be slower.
11
But how is the structure represented in memory by the compiler?
12
The structure is represented as a series of consecutive values, each starting at a specific padding from the beginning of of the structure.
13
The padding is needed so that each value is correctly aligned.
14
As you can see here, the value D would occupy only one byte, but three extra bytes are added so that the value C is correctly aligned.
15
If we add another character at the end of the structure, another 3 bytes of padding are added because the whole structure must be aligned to the alignment of the structure itself,
16
which is the maximum alignment between the members of the structure.
17
This way, when creating an array of this structure, the first member is always correctly aligned.
18
So to save memory, we can move our characters close together
19
so that only 2 bytes of padding are added making the whole thing 16 bytes instead of 20, while keeping everything correctly aligned.
20
We can check that in C as well.
21
As you can see, this code represents what was shown in the previous images.
22
Now take a look at the output of this.
23
If we move E, like this, the output changes.
24
Now if you want to ignore alignment and remove padding for some reason, you can use the packed attribute like this on GCC and CLang and the compiler will not insert any padding,
25
as you can see here from this output, but note that on some architectures this might make the code slower.
26
So in conclusion, if you don't wanna waste memory over padding, remember to place your structural members correctly.
27
Bye!
FOR YOU
推薦影片
背景與概述
在這段影片中,講者深入探討了記憶體管理和結構體對齊的問題。他使用C語言的示例來展示如何通過調整結構體成員的排列來節省記憶體,同時解釋了記憶體對齊的必要性。通過這種方式,學習者不僅能夠理解程式設計中的記憶體概念,還能在處理更復雜的程式碼時更有效地使用記憶體。此外,這段影片也揭示了在特定情況下如何利用“packed”屬性來去掉填充,從而提升效能。
日常交流中的五個重要短語
- 記憶體對齊 (Memory Alignment)
- 填充位元組 (Padding Bytes)
- 結構體 (Structure)
- 連續值 (Consecutive Values)
- 效能提升 (Performance Improvement)
逐步影子跟讀指導
要有效提升你的英語發音和口語能力,可以通過以下步驟進行影片的英語影子跟讀練習:
- 觀看影片時,專注聽懂講者的表達及其語調。在此過程中,你可以通過看YouTube學英語的方法不斷練習。
- 暫停影片,嘗試重複講者所說的每一句話,模仿其發音和語調。這種方法能幫助你提高英語發音,並在瞬間提升口語使用的準確性。
- 注意影片中提到的技術名詞和短語,嘗試將其應用到自己的句子中,這對雅思口語練習也是非常有幫助的。
- 反覆練習時,記錄下自己的發音與講者的發音之間的差異。利用這種方法,你可以更新自己的發音方式,形成新的shadowspeak習慣。
- 最終,結合影片的實際內容,嘗試與其他學習者一起進行討論或分享你的理解,以此加深記憶。
通過這樣系統的練習,你不僅能夠掌握特定的程式語言概念,也能夠提高你的英語口語能力,從而實現多贏的效果。
什麼是跟讀法?
跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。











