Contachit
Page Navigation

Top of Page The 3 different kinds of variables.
  1. 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".
  2. 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".
  3. 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.

Top of Page Create "automatic" variable.

[code screenshot]

Top of Page Create "pointer" variables.

[code screenshot]

Top of Page Create "view_pointer" variables.

[code screenshot]

Top of Page Delete "pointer" memory, by setting it null.

[code screenshot]

Top of Page Transfer "pointer" memory between two pointers.

[code screenshot]

Top of Page Pass "pointer" as function argument, which expects "pointer".

Notes:
[code screenshot]

Top of Page Pass "pointer" as function argument, which expects "view_pointer".

Notes:
[code screenshot]

Top of Page Pass "view_pointer" as function argument, which expects "view_pointer".

Notes:
[code screenshot]