I'm currently wroking on a "memory project" at school, more precisely about dynamic memory allocation. My problem is about the Heap management. I don't really understand the difference between memory pages and memory blocks. Please correct me if i'm wrong : The heap contains some unmapped map. When we try to allocate some memory, the asked size becomes a mapped region of the heap that we can use. This new region seems to contain some "memory pages" of 4096 Bytes but i don't understand where the memory "blocks" are...
-
What do you mean by an "unmapped map"? – Scott Hunter Jan 28 '16 at 14:55
-
@ScottHunter Think of it as a mental map. It's what Lewis & Clark had of America when they started. – Peter - Reinstate Monica Jan 28 '16 at 14:56
-
My bad, i wanted to say unmapped region, and sorry for my bad english :/ – Guillaume Jan 28 '16 at 14:59
-
I do not think that you need to deal with memory pages (as explained in cad's answer). Modern operating systems have functions which "give memory to the process" (e.g. `sbrk()`); the process can be oblivious about how exactly that is done. Most likely the school project's goal is to re-implement a malloc/free implementation and thus understand how it typically works internally. *Getting* memory from the operating system is the least of your worries. – Peter - Reinstate Monica Jan 28 '16 at 15:03
1 Answers
Memory pages are a term used in virtual memory management. It is the smallest unit addressable by the MMU (Memory Management Unit), which converts virtual addresses (to logical addresses, on x86, and) to physical addresses. For more information on pages and virtual memory management, read how x86 paging works.
Memory blocks are not that tightly tied to a certain topic. They can refer to virtually everything and are used when referring to memory colloquially (in case anybody talks OSes colloquially).
As far as I can tell, they refer to the blocks allocated by a user on the free store a.k.a. heap here. They are the memory area allocated by users of an API providing functionality to access a heap (like the C standard library with malloc
, free
, etc.).
-
Another possible use of _Memory blocks_ are blocks managed by heap management functions in the standard library, including both _free_ and _allocated_ blocks. An implementation might split free blocks when the program is allocating a block of smaller size, and might recombine free blocks into larger blocks when the program is freeing a previously allocated block. – Ian Abbott Jan 28 '16 at 16:42