Locks-and-keys
Encyclopedia
Locks-and-keys is a solution to dangling pointer
s in computer programming language
s.
The locks-and-keys approach represents pointers as ordered pairs (key, address) where the key is an integer value. Heap-dynamic variables are represented as the storage for the variable plus a cell for an integer. When a variable is allocated, a lock value is created and placed both into the variable's cell and into the variable's ordered pair. Every access to the pointer compares these two values, and access is allowed only if the values match.
When a variable is deallocated, the key of its ordered pair is modified to hold a value different from the variable's cell. From then on, any attempt to dereference the pointer can be flagged as an error. Since copying a pointer also copies its cell value, changing the key of the ordered pair safely disables all copies of the pointer.
Dangling pointer
Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations....
s in computer programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s.
The locks-and-keys approach represents pointers as ordered pairs (key, address) where the key is an integer value. Heap-dynamic variables are represented as the storage for the variable plus a cell for an integer. When a variable is allocated, a lock value is created and placed both into the variable's cell and into the variable's ordered pair. Every access to the pointer compares these two values, and access is allowed only if the values match.
When a variable is deallocated, the key of its ordered pair is modified to hold a value different from the variable's cell. From then on, any attempt to dereference the pointer can be flagged as an error. Since copying a pointer also copies its cell value, changing the key of the ordered pair safely disables all copies of the pointer.