Contachit
Page Navigation
-
Automatic
- Memory for this type of variable always exists while it's in scope, and is automatically deleted when the scope is existed.
- Pointer variables (of any kind) will NEVER point to this type of variable.
- In C++ terms, this is "stack memory".
-
Pointer
- This type of pointer ALWAYS owns the memory it refers to (if any).
-
You never have to manually delete this memory (like you would in C++). The memory is automatically deleted when variable goes out of scope,
or is set to 'null'.
- A "pointer" variable will NEVER point to a "view_pointer" variable.
- No two "pointer" variables ever refer to the same memory.
-
Consider "pointer" variables x and y. If x is told to point to y, the memory x used to refer to
is deleted, and ownership of memory y refers to is transferred to x, and y is set to null.
-
If memory a "pointer" refers to is ever deleted, any "view_pointer" which referred to this variable, is set to null. This prevents
accessing memory which has been deleted. Note: This was the case when Contachit translations used "smart pointers", but was broken
when I switched to "raw pointers". I plan to fix this one way or another.
- In C++ terms, a "pointer" refers to "heap memory".
-
View_Pointer
- This type of pointer NEVER owns the memory it refers to.
- [0..n] "view_pointer" can refer to a single "pointer" variable.
-
If a "view_pointer" refers to a "pointer", and the "pointer" transfers ownership to a different "pointer" variable, the
"view_pointer" will automatically now refer to the "pointer" variable which owns the memory. Note: This was the
case when Contachit translations used "smart pointers", but was broken when I switched to "raw pointers". I plan to fix this one way or another.
Notes:
- The highlighted parts, are what you need to pay most attention to. The code comments have useful info as well.
-
Because the function called has formal argument of variable type pointer, the memory of variable 'x' is transferred to
the formal argument.
Notes:
- The highlighted parts, are what you need to pay most attention to. The code comments have useful info as well.
-
Because the function called has formal argument of variable type view pointer, the variable 'x' maintains
ownership of the memory after the function call.
-
The opposite is NOT valid. That is, you can't pass a "view pointer", as an argument when a "pointer" is expected.
Notes:
- The highlighted parts, are what you need to pay most attention to. The code comments have useful info as well.
-
The function called expects a "view pointer", and is passed a "view pointer". No transfer of memory ownership occurs.
- Basically, both "view pointer" variables, 'x' and 'y', both refer to memory owned by the object "abc::Robot".
© 2023 Isaac Benson Powell