تدريب Shadowing: 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. من خلال دراسة كيفية عمل الهياكل وأثرها على استخدام الذاكرة، ستتمكن من تدعيم معرفتك باللغة الإنجليزية التقنية واستخدام التعبيرات المرتبطة بموضوع البرمجة. ستساعدك هذه المعرفة في ممارسة المحادثة الإنجليزية مع زملائك أو أثناء التعلم من مقاطع الفيديو على يوتيوب، مما يعزز مهاراتك في التحدث والفهم.

المفردات والعبارات الرئيسية

  • محاذاة الذاكرة - Memory alignment
  • بايت - Byte
  • الهيكل - Structure
  • تخزين - Storage
  • تعبئة - Padding
  • المعالج - Compiler
  • سماحيات - Alignments

نصائح للممارسة

لتحقيق أقصى استفادة من هذا الفيديو، احرص على اتباع أسلوب "ممارسة المحادثة الإنجليزية" عبر shadowspeak. ابدأ بتقليد النطق والإيقاع بسرعة، خاصةً أن ذلك سيساعدك على فهم النص بشكل أفضل. احرص على التوقف في كل نقطة حيث يتحدث المتحدث وكرر ما قاله بصوت عالٍ. حاول أيضاً التركيز على العبارات التقنية والمصطلحات الجديدة (مثل "محاذاة الذاكرة" و"بايت")، حيث أن هذه العناصر تساعد كثيراً في تعميق فهمك للموضوع.
قم بمراقبة نبرة المتحدث، حيث تتميز بالوضوح والتركيز. حاول تقليد هذه النبرة لأن الاحتفاظ بها سيعزز طريقة حديثك. عندما تتفاعل مع المحتوى، سيكون لديك القدرة على تدوين الملاحظات حول الاستخدام الشائع للمفردات، مما يساهم في تعزيز تجربتك في تعلم الإنجليزية مع يوتيوب. بهذا الشكل، ستستفيد من المهارات المكتسبة وتستطيع التألق في تقديم أفكارك وتبادل الحديث حول موضوعات تقنية مع الآخرين. استمتع بممارستك!

ما هي تقنية التظليل الصوتي؟

التظليل الصوتي (Shadowing) تقنية تعلم لغة مدعومة علمياً، طُورت أصلاً لتدريب المترجمين الفوريين المحترفين. الطريقة بسيطة لكنها قوية: تستمع لصوت إنجليزي أصلي وتكرره فوراً بصوت عالٍ — كظل يتبع المتحدث بتأخير 1-2 ثانية. تُظهر الأبحاث تحسناً كبيراً في دقة النطق والتنغيم والإيقاع وربط الأصوات والاستماع والطلاقة.