0Pricing
Mojo Academy · درس

دلالات النسخ مقابل النقل

كيف تُكرّر القيم أو تُنقل

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

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

Two Ways to Pass Along

When a value moves around your program, Mojo can either copy it or move it. Knowing which happens helps you reason about cost. 🔁

What a Copy Is

A copy makes a brand-new, independent value. Both the original and the copy live on, each owning its own data.

var a = MyType(1)
var b = a   # copy: a still valid

What a Move Is

A move relocates a value instead of duplicating it. The data is handed over, so the source is no longer used afterward.

Why Moves Are Cheaper

A copy may duplicate heap data, but a move just transfers ownership of what is already there. For big values that saves real work.

Assignment Usually Copies

Plain assignment in Mojo defaults to a copy, so each variable owns its own value. This keeps value semantics safe and predictable.

Triggering a Move

You request a move with the transfer operator, the caret sigil. It tells Mojo to hand the value over rather than duplicate it.

var b = a^   # move a into b

The Source Is Spent

After a move, the source variable is consumed. Mojo will not let you read it again, which prevents using stale or invalid data.

Copies Keep Both Alive

By contrast, after a copy both variables are fully usable. Each one is independent, so editing one never touches the other.

The Compiler Decides Smartly

Mojo can also turn a copy into a move automatically when the source is no longer needed, an optimization that quietly saves work.

Cost Awareness Pays Off

Thinking about copy versus move lets you avoid duplicating large buffers by accident. It is the first step toward efficient Mojo code.

You Stay in Control

Mojo gives you safe defaults but lets you opt into a move when you want speed. You choose the behavior that fits each moment.

Quick Check

Lets test copy versus move.

Recap

A copy makes an independent duplicate, while a move transfers ownership cheaply and spends the source. Now you can predict both. 🎯

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

هل درس «دلالات النسخ مقابل النقل» مجاني؟

نعم — نص درس «دلالات النسخ مقابل النقل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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. دالة __copyinit__
  3. دالة __moveinit__
  4. التدمير و__del__
← العودة إلى Mojo Academy