ECS 30 Lecture Notes - Lecture 21: Compile Time
Lecture 21
Dynamic memory allocation
- clean up the space being used for variables and other data storage
- compile time variables are automatically deallocated based on their known extent
Free()
- Void free()
o Provided by header stdlib.h
o Frees allocate area pointer by ptr
Calloc()
- Malloc() only allocates certain number of bytes
- Calloc() allocates certain number of item
3 phase schemes
- Allocation of data
- Computation involving data
- Free data
Realloc()
- Increase and decrease size of space pointed by prt
-
- Useful approach for dynamic arrays
See powerpoint for 1D array, 2D array and string
Below is from powerpoint reference:
find more resources at oneclass.com
find more resources at oneclass.com