Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1And in Conclusion\dots

C does not automatically handle memory for you, so it’s up to you, the programmer, to allocate, use, and free memory correctly. In each program, an address space is set aside, separated into 2 dynamically changing regions and 2 ‘static’ regions.

There are a number of functions in C that can be used to dynamically allocate memory on the heap. The following are the ones we use in this class:

Be careful when allocating buffers on the stack and heap! The heap is the biggest source of subtle bugs in C code.

Take CS 162 for more!

2Textbook Reading

K&R 7.8.5, 8.7

3Additional References

4Exercises

Check your knowledge!

4.1Conceptual Review

  1. True/False: Memory sectors are defined by the hardware, and cannot be altered.

  1. What’s an example of this process that might need significant stack space, but very little text, static data, and heap space?

  1. What’s an example of a text- and static data- heavy process?

  1. What’s an example of a heap-heavy process?