User Tools

Site Tools


notes:discrete:fall2023:projects:ttb0

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
notes:discrete:fall2023:projects:ttb0 [2023/09/13 17:26] – [ACCESSING WITH POINTER ARITHMETIC] walleynotes:discrete:fall2023:projects:ttb0 [2023/09/14 03:50] (current) – [MALLOC] jhimmel2
Line 17: Line 17:
  
 Malloc is used to allocate memory for specific purposes. For breakout, since we'll know how many bricks are going into our brick field, we'll use an array. An array is always the same size, which means the amount of memory used for the array will remain constant. Malloc is perfect for this scenario. Malloc is used to allocate memory for specific purposes. For breakout, since we'll know how many bricks are going into our brick field, we'll use an array. An array is always the same size, which means the amount of memory used for the array will remain constant. Malloc is perfect for this scenario.
 +
 +When the malloc() function is called, it sends a request to the heap in the form of a memory block (heap is memory allocated for each program). The heap's available memory must be at least equivalent to the memory block size.  In this case, it will assign the malloc() that memory size function against its request. If the heap has no memory, null value is returned. The memory block is cleared using the free() function to free up the memory for other program instructions.
 =====MALLOC’ED ARRAY===== =====MALLOC’ED ARRAY=====
 For Breakout, we need to allocate the amount of memory needed to hold our entire brick field (AKA the array of brick structs). We do that by using the ''sizeof'' function: For Breakout, we need to allocate the amount of memory needed to hold our entire brick field (AKA the array of brick structs). We do that by using the ''sizeof'' function:
notes/discrete/fall2023/projects/ttb0.1694626006.txt.gz · Last modified: 2023/09/13 17:26 by walley