跟读练习: You are wasting memory - 通过视频学习英语口语

正在创建课程...
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!

背景与概述

在这段视频中,讲者深入探讨了内存管理和结构体对齐的问题。他使用C语言的示例来展示如何通过调整结构体成员的排列来节省内存,同时解释了内存对齐的必要性。通过这种方式,学习者不仅能够理解编程中的内存概念,还能在处理更复杂的代码时更有效地使用内存。此外,这段视频也揭示了在特定情况下如何利用“packed”属性来去掉填充,从而提升性能。

日常交流中的五个重要短语

  • 内存对齐 (Memory Alignment)
  • 填充字节 (Padding Bytes)
  • 结构体 (Structure)
  • 连续值 (Consecutive Values)
  • 性能提升 (Performance Improvement)

逐步影子跟读指导

要有效提升你的英语发音和口语能力,可以通过以下步骤进行视频的英语影子跟读练习:

  1. 观看视频时,专注听懂讲者的表达及其语调。在此过程中,你可以通过看YouTube学英语的方法不断练习。
  2. 暂停视频,尝试重复讲者所说的每一句话,模仿其发音和语调。这种方法能帮助你提高英语发音,并在瞬间提升口语使用的准确性。
  3. 注意视频中提到的技术名词和短语,尝试将其应用到自己的句子中,这对雅思口语练习也是非常有帮助的。
  4. 反复练习时,记录下自己的发音与讲者的发音之间的差异。利用这种方法,你可以更新自己的发音方式,形成新的shadowspeak习惯。
  5. 最终,结合视频的实际内容,尝试与其他学习者一起进行讨论或分享你的理解,以此加深记忆。

通过这样系统的练习,你不仅能够掌握特定的编程语言概念,也能够提高你的英语口语能力,从而实现多赢的效果。

什么是跟读法?

跟读法 (Shadowing) 是一种有科学依据的语言学习技巧,最初开发用于专业口译员的培训,并由多语言者Alexander Arguelles博士普及。这个方法简单而强大:您在听英语母语原声的同时立即大声重复——就像是一个延迟1-2秒紧跟说话者的影子。与被动听力或语法练习不同,跟读法强迫您的大脑和口腔肌肉同时处理并模仿真实的讲话模式。研究表明它能显着提高发音准确性,语调,节奏,连读,听力理解和口语流利度——使其成为雅思口语备考和真实英语交流最有效的方法之一。