Friday, 16 October 2015

Session 4

Recursion is what it is called when a function calls itself. Like a paradox
If the base case (is = 0 etc) doesn't stop it will last forever!
If it is on the stack it will overflow and cause major problems at runtime.
Recursive calls can slow down memory - if they are endless, there could be millions of things happening at the same time... even if you have enough space for them all

A continuous (contiguous - in a row) block of memory is required for a static array
Static arrays are a fixed size, hence static (which means lacking movement, change etc)
Due to this, there might be memory allocated that is never used...

Dynamic arrays also require contiguous memory blocks but the size is not fixed - the size can change as required, so as not to waste any memory, and to never have too high a quantity
example array syntax: Item inventory [2] [5]; this is a table with 2 rows and 5 columns

Dynamic arrays should be constant (const) referenced if variable is not going to be changed
Cannot have null references and they must be initialised when created
And only return references and pointers when you know the data is still valid.



No comments:

Post a Comment