Week 5 - Complex Data Types & Memory Flashcards
What is a primitive data type?
The basic types of data which come default with the programming language.
Eg: boolean, float/real, int, string etc.
What’s the difference between an array and a class/record?
A class/record is used to define the blueprint of a general things. This doesn’t contain any actual values.
However, an array is used for storing multiple variables and values.
Pass by Value
Takes a copy of the variable and passes it to the called function or procedure.
Passes only the value of the variable.
Like downloading Word Doc to edit on your own. Changes made are independent of the main doc.
Pass by Reference
Takes a copy of the link to the content passes it to the called function or procedure.
Passes the actual variable and value.
Like emailing a link to a Google Docs which allows for everyone to make changes to the main document.
What are the main parts of memory?
The code area, global variables, the stack and the heap.
What are pointers and references used for?
Pointers/references are found on the stack, and link to a value or variable on the heap.
Can you assign values to fields once you define a type?
No. Because you need to first initialise the values.
This is where you have the placeholder values, so that you can then pass values into that class/function.
What are the main ways of using complex and custom data types in Ruby?
Classes/records, structs & modules/enumerations.
The Stack
A part of the computer memory responsible for storing function calls and local variables.
The Heap
It’s a large pool of memory where the running program can request chunks of memory.
This is typically used alongside pointers and references on the stack to point to memory on the heap.
This is typically called dynamic allocation.
Code Area
Where class definitions go and main code goes.
This area of memory is fixed.
Global Variables
Where all global variables and constants accessible to all functions are stored in the computer memory.
This area of memory is fixed.
What’s the difference between the stack and the heap?
The stack is a linear data structure, whereas the heap is a hierarchical data structure.
The stack is fixed, whereas the heap is dynamic and can change throughout the runtime of a program.
Enumerations
Modules define an enumeration which is a custom data type.
They are not not like classes or structs because they are created as a set of constants.
Attributes
Used to define data/special characteristics of a class/record. They make up the blueprint of our class.