CS50x - Week 4

Memory

·

2 min read

Introduction

Reflecting on my initial expectations when I started learning Harvard's CS50X, I am delighted to say that they have been far exceeded. This week specifically learning about the inner workings of computer memory and how it influences programming has been an eye-opener.

Why care about the computer's memory when programming?

Understanding memory during programming is crucial because it is where data is manipulated and stored. This week I learned about the concept of memory addresses, which are unique identifiers for each byte of memory.

Pointers

They are variables that store memory addresses. Pointers are variables that contain the address of some value. Pointers are a powerful tool that allows programmers to access and manipulate data indirectly by pointing to the memory locations where data is stored. Pointers can however lead to segmentation fault if not carefully handled.

Memory allocation and deallocation

I learned about malloc() and free() which are used in C for memory allocation and deallocation. Learning how memory can be requested, used, and then released to prevent leaks and optimize memory usage was fascinating

I also learned about the Valgrind which is a tool that can check to see if there are memory-related issues with your programs wherein you utilized malloc. It specifically checks to see if you free all the memory you allocated.

Conclusion

The lab exercises and problems reinforced my understanding of memory concepts. I got to work with pointers, dynamically allocate memory and write programs that manage memory resources effectively. I look forward to applying these concepts in future projects.