r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

2

u/Spudboy4800 Apr 05 '22

Shared memory, especially in systems (mmap, shm_open etc)

1

u/BenardoDiShaprio Apr 06 '22

Each program has its own private memory, and they are unable to access other program memories. The only program that can access all the program memories is the OS.

Shared memory is memory that the OS requests from the RAM, that allows to be shared accross multiple programs. Processes would can access/create this shared memory using a variety of OS functions/system calls (like mmap, shm_open, etc).

So if you write 2 C programs, and u want one program to talk to another, you need them to share memory because otherwise there is no way for each program to know what happens with the other.