التخزين والذاكرة والمكدس
مواقع بيانات EVM
التخزين والذاكرة والمكدس درس مجاني في Web3 & DApp Development Fundamentals على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web3 & DApp Development Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Where Data Lives in the EVM
The EVM has several distinct places to keep data, each with different costs and lifetimes.
The three core data locations are the stack, memory, and storage. Choosing the right one is key to writing efficient contracts.
The Stack
The stack is the EVM's scratchpad for computation. It holds up to 1024 values of 256 bits each.
Opcodes push and pop from the top of the stack. It is extremely cheap but tiny and temporary.
PUSH1 0x02 // [2]
PUSH1 0x04 // [2, 4]
MUL // [8]
// stack vanishes when the call endsMemory
Memory is a temporary, linear byte array that exists only during a single transaction call.
It is used for things too big for the stack, like building a string or an array. It resets to empty when the call finishes.
memory[0x00..0x20] = some value
// readable/writable during the call
// erased after execution endsStorage
Storage is the contract's permanent state, kept on the blockchain between transactions.
It is a key-value store mapping 256-bit slots to 256-bit values. State variables in a contract live here.
storage slot 0 -> owner address
storage slot 1 -> total supply
storage slot 2 -> paused flag
// persists forever on-chainCost Comparison
Cost rises sharply by location:
- Stack — cheapest, a few gas per op
- Memory — cheap, grows with size
- Storage — very expensive, especially first writes
Why Storage Is Expensive
Storage writes are costly because every node must persist them forever. A fresh storage write (SSTORE) can cost 20000 gas.
This is why developers minimize storage writes and prefer memory for temporary work.
Storage Slots and Packing
Storage is organized into 32-byte slots. Smaller variables can be packed into one slot to save gas.
For example, two uint128 values fit together in a single 256-bit slot.
slot 0: [ uint128 a | uint128 b ]
// two values packed into one slot
// saves a storage slot = saves gasCalldata
A fourth location, calldata, holds the read-only input data of a transaction or call.
It is the cheapest place to read function arguments and cannot be modified, making it ideal for inputs you only need to read.
Choosing the Right Location
Rules of thumb:
- Use the stack for short-lived computation
- Use memory for temporary structures
- Use storage only for data that must persist
- Use calldata for read-only inputs
Lifetime Summary
Each location has a different lifetime:
- Stack and memory — die when the call ends
- Storage — persists permanently on-chain
- Calldata — exists for the duration of the call, read-only
Putting It Together
The EVM separates data into stack, memory, storage, and calldata, ordered roughly from cheapest and shortest-lived to most expensive and permanent.
Smart developers keep persistent storage writes to a minimum.
Quick Check
Test your knowledge of EVM data locations.
Recap: Storage, Memory, Stack
You learned that:
- The stack is cheap, tiny, and temporary
- Memory is temporary scratch space for a call
- Storage is permanent but expensive
- Calldata is cheap, read-only input
Next: opcodes in detail.
الأسئلة الشائعة
هل درس «التخزين والذاكرة والمكدس» مجاني؟
نعم — نص درس «التخزين والذاكرة والمكدس» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web3 & DApp Development Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.
ماذا ستتعلم في «التخزين والذاكرة والمكدس»؟
مواقع بيانات EVM تتمرن على Web3 & DApp Development Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Web3 & DApp Development Fundamentals؟
لا تُشترط خبرة سابقة. Web3 & DApp Development Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «التخزين والذاكرة والمكدس»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Web3 & DApp Development Fundamentals هذا؟
نعم. كل درس في Web3 & DApp Development Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- آلة Ethereum الافتراضية
- التخزين والذاكرة والمكدس
- Opcodes
- الحسابات والحالة