02 Move Language and Variables#
Variables#
-
Variables: named objects;
-
Objects: memory regions that store values of a certain type; (similar to pointers in C++)
-
Values: collections of bytes interpreted according to their type;
-
Types: define the possible values and operations
Storage#
-
Value types
-
Stored on the stack
-
Simple types: boolean, integer, floating point...
-
-
Reference types
-
Stored on the heap
-
Complex types: objects, arrays, classes, functions...
-
When we define a variable as an object, its value is stored on the heap, and the index of its heap memory is stored on the stack, with the index on the stack pointing to the reference type data stored on the heap. (Variable points to object)
Core Differences in Move#
In terms of the relationship between value types and reference types, it differs from other languages in terms of indexing. Instead, it uses "ownership" as the operation for reference types.
-
Ownership can only be held by one "person" at a time;
-
Ownership can be transferred to other variables;
For example:
B = A;
C = B;
At this point, B is empty, and C points to A.
Benefits of this approach:
-
Avoids memory leaks, unlike other languages, memory can be reclaimed at compile time;
-
Improves memory usage efficiency by avoiding unnecessary copying of reference types;
-
Better readability and maintainability;
03 The Four Major Types: uint, String, Bool, address#
uint Type#
Multiple ways to write it
Bool Type#
String Type#
address Type#
The output is @0×2a, but zeros are automatically padded in between.