0Pricing
Mojo Academy · درس

المكدس مقابل الكومة ببساطة

أين توجد القيم ولماذا يهم ذلك

المكدس مقابل الكومة ببساطة درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Two Places for Data

Every value in your program lives somewhere in memory. Mojo uses two regions: the stack and the heap. 🧠

The Stack

The stack is a fast, orderly pile of memory. Local variables go here, and they vanish automatically when a function returns.

Why the Stack Is Fast

The stack is fast because its size is known and it grows and shrinks in a simple last-in, first-out order, like a stack of plates.

The Heap

The heap is a larger, flexible pool of memory. You use it when a value's size is not known until the program is actually running.

When You Need the Heap

A list that grows, a long string, or anything sized at runtime lives on the heap, since the stack needs fixed, known sizes.

Small, Fixed Values

A simple Int or Float has a fixed, tiny size, so Mojo can keep it right on the stack for the fastest possible access.

var count: Int = 7

Growing Data

A List can grow without limit, so its elements live on the heap while a small handle to them sits on the stack.

var nums = List[Int](1, 2, 3)

Speed Trade-Off

The heap is more flexible but slower to manage than the stack. Reaching for heap memory has a real cost you should respect.

Automatic Cleanup

Stack values clean themselves up at the end of their scope. Mojo also tracks heap values so they are freed at the right time for you.

You Rarely Choose by Hand

Most of the time Mojo decides stack or heap based on the type. Knowing the difference simply helps you reason about speed.

A Mental Model

Picture the stack as a quick scratchpad and the heap as deep storage. Fast and small versus large and flexible.

Quick Check

Let us see where a growable value lives.

Recap

The stack is fast and fixed-size; the heap is flexible for runtime-sized data. Knowing both helps you reason about speed. 🎯

الأسئلة الشائعة

هل درس «المكدس مقابل الكومة ببساطة» مجاني؟

نعم — نص درس «المكدس مقابل الكومة ببساطة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «المكدس مقابل الكومة ببساطة»؟

أين توجد القيم ولماذا يهم ذلك تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «المكدس مقابل الكومة ببساطة»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. المكدس مقابل الكومة ببساطة
  2. المؤشرات بلا خوف
  3. امتلاك مخازن الكومة
  4. تجنب أخطاء الذاكرة الشائعة
← العودة إلى Mojo Academy