Pointers Flashcards

(18 cards)

1
Q

In memory, what is “The Stack”?

A

a section of memory where the current code is sitting on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the 3 ways to pass data into functions?

A

Pass by:

Value (no symbols)
Reference (& symbol)
Pointer (* symbol)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what happens when you call a function?

A

your program places 8 bytes (the function address) onto The Stack.

If the function has no params, then only those 8 bytes will be pushed onto The Stack and will free once the program is done. If there are params, then they are also pushed onto The Stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what happens when you pass in those 3 ways?

A

Pass By Value = the object is COPIED into The Stack, it’s not the original object

Pass By Reference/Pointer = 8 Bytes are placed, no matter the size of the object. You are passing in a memory address to that object.

Anything above 8 Bytes, best off using a Reference/Pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

why pass in pointers and refs instead of value?

A

saves time and memory

anything larger than an FVector passed by const reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does the const modifier do?

A

it basically means, “this cannot be modified”

modifying a reference to something will modify the original data itself, sometimes we dont want this happen

Function(const int& variable) = “this variable cannot be modified, its constant”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

why use references over pointers?

A

pointers can null (non existing) and a reference cannot be null (something has to exist to be referred too)

use a pointer for objects where being null is a potential state in the world.

always check to see if that object is null 
if (object != nullptr) 
{
do stuff
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do you pass in a UObject?

A

pass in by Pointer (99%) of the time, 1% by Reference if for good eason

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is some useful pointer knowledge?

A

can be null

have a memory address

can be changed to point at something else other than the previous pointed object

you cant point to a reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

some useful Reference knowledge?

A

can reference a pointer of the object in memory itself

has no address, thus cant assign a pointer to it

once you declare it, you can’t change it to reference something else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what do pointers give you?

A

speed

power

control

a living connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how do you get the memory address for a pointer?

A

you use the & (address of) symbol

FVector = X = FVector (1, 1, 1);
FVector* Xptr = nullptr;
Xptr = &X;

Xptr now points to memory address of X.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what must you remember about pointers?

A

you must always check to see if that thing exists first - check for nullptrs

return out of the function for a “silent” fail case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how do you do access the data in a pointer?

A

you must dereference to access the data

Deference with * or ->

(using previous example…)

FVector NewVector = FVector::ZeroVector;
if (X)
NewVector = *X

or

if(X)
const float XValue = X->Value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

reason 1 for using a pointer?

A

gives you access to memory locations that miles away - you dont need to use 100x Get() sequences to grab something

e.g. GetGalaxy()->GetSolarSystem()->GetPlanet()->GetMainCharacter()->GetCurrentArmor().Durability; GetGalaxy()->GetSolarSystem()->GetPlanet()->GetMainCharacter()->GetCurrentArmor().Color; GetGalaxy()->GetSolarSystem()->GetPlanet()->GetMainCharacter()->GetCurrentArmor().Size;

INSTEAD

you can just use this once:

FArmorStruct* TheArmor = & GetGalaxy()->GetSolarSystem()->GetPlanet()->GetMainCharacter()->Armor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

reason 2 for using a pointer?

A

you can access huge quantities of data at any time.

the pointer points the location in memory, that actual amount of memory involved could be massive

17
Q

reason 3 for using a pointer?

A

it stays current and gives you a living connection to that object.

you dont need to duplicate any data, you have a direct connection to it.

18
Q

whats the safe approach to passing in data?

A

pass by reference where possible, instead of pointers

pass UObjects by pointers 99& of the time