Monday, 26 October 2015

Low Level Programming Session Summary 5, 26th October

Low Level Programming Session Summary

26th October

This session of low level programming we covered smart pointers as well as casting and memory management techniques.

Smart pointers are a unique kind of pointer that is able to manage itself and self delete. They are essentially self managing and also have unique properties that can be exploited by the programmer. They are not without their weaknesses though. 

The first smart pointer is a unique pointer. They are used in the same way as normal pointers are and have the same size and set of instructions as a regular pointer, however they differ as that pointer owns that part of memory. No other pointers go to that part of memory, except the unique pointer. If two unique pointers point to the same address then one should be deleted. It is possible to move the ownership of unique pointers, but the previous pointer must be deleted. However, if it is, then problems may occur.

The second smart pointer is a weak pointer which adds a tenuous link to a block of memory. It cannot access that part of memory, however it can read data from that block of memory. It can give you a memory address, but it can't actually access that part of memory. It can check to see if the object exists in memory, and it also doesn't own that part of memory.

The last smart pointer is a shared pointer which allows a group of pointers access to that block of memory. It also tracks how many accesses there has been to that part of memory and store it in a part of memory. This means that shared pointers are at least twice as big as a normal pointer.

Static casting is a way of implicitly converting between data types, transferring a float to an integer for an example, and vice versa. This is useful when you need to convert data types, however it is risky as sometimes the complier will not recognise data.

Dynamic casting is a way of converting between data types up and down a class structure, a safe way of converting. This way one can still be bound by a class structure, but one can still cast up and down it. There are still issues, but it is safer than a static cast.

I'm a little unsure about these new pointers and casting techniques, however I am sure I will get them with practice. 

No comments:

Post a Comment