This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:fall2024:projects:msi1 [2024/09/19 01:02] – [pointer arithmetic] cburling | notes:fall2024:projects:msi1 [2024/09/19 03:39] (current) – [malloc] bpatrice | ||
---|---|---|---|
Line 3: | Line 3: | ||
The primary difference between the last and current project is that instead of using arrays, linked lists are to be employed instead. Essentially, | The primary difference between the last and current project is that instead of using arrays, linked lists are to be employed instead. Essentially, | ||
=====malloc===== | =====malloc===== | ||
+ | You start with nothing, then there is the great sneeze! Or in this case the malloc! At this point you should all know that malloc is memory allocation. In the Joe O classes you may be familiar with the term //Newed Up//? It's essentially that. | ||
< | < | ||
- | start = (Sprite *) malloc( sizeof (Sprite)); | + | Sprite* Node |
+ | Node = (Sprite*)malloc(sizeof(Sprite)); | ||
</ | </ | ||
- | When making | + | Congratulations you now have a Node! You might also find it useful |
+ | |||
+ | Also, remember that whenever you allocate memory(malloc) you are also responsible for freeing that memory at the end of your program. | ||
+ | You can do this by using | ||
+ | < | ||
+ | free(Node); | ||
+ | </ | ||
=====pointer arithmetic===== | =====pointer arithmetic===== | ||
With Lists and Nodes, unlike Arrays since elements are not stored contiguously, | With Lists and Nodes, unlike Arrays since elements are not stored contiguously, |