User Tools

Site Tools


notes:fall2024:projects:msi1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:fall2024:projects:msi1 [2024/09/19 01:02] – [pointer arithmetic] cburlingnotes: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, all instances of arrays in msi0 must now be retired in favor of the singly linked list. This game will utilize new struct attributes and functions to achieve this goal. The end product should feature ZERO arrays, and, if done correctly, one or more linked lists (pending designer preference). The primary difference between the last and current project is that instead of using arrays, linked lists are to be employed instead. Essentially, all instances of arrays in msi0 must now be retired in favor of the singly linked list. This game will utilize new struct attributes and functions to achieve this goal. The end product should feature ZERO arrays, and, if done correctly, one or more linked lists (pending designer preference).
 =====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.
 <code> <code>
-start = (Sprite *) malloc( sizeof (Sprite));+Sprite* Node 
 +Node = (Sprite*)malloc(sizeof(Sprite));
 </code> </code>
-When making node it is best to malloc it.+Congratulations you now have Node! You might also find it useful to have a List so List struct and malloc that in the same manner. 
 + 
 +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 
 +<code> 
 +free(Node); 
 +</code> 
 =====pointer arithmetic===== =====pointer arithmetic=====
 With Lists and Nodes, unlike Arrays since elements are not stored contiguously, you can't simply add the size of the element to the address to reach the next. While it is faster to do it that way, this project is about Lists and thus we will do it this way.\\   With Lists and Nodes, unlike Arrays since elements are not stored contiguously, you can't simply add the size of the element to the address to reach the next. While it is faster to do it that way, this project is about Lists and thus we will do it this way.\\  
notes/fall2024/projects/msi1.1726707762.txt.gz · Last modified: 2024/09/19 01:02 by cburling