Memory management 进程的内存分配

Memory management 进程的内存分配,memory-management,process,operating-system,Memory Management,Process,Operating System,我阅读了以下关于进程内存分配的行: One of the important considerations in main memory management is: how should an OS allocate a chunk of main memory required by a process. One simple approach would be to somehow create partitions and then different processes c

我阅读了以下关于进程内存分配的行:

  One of the important considerations in main memory management is: how should an
  OS allocate a chunk of main memory required by a process. One simple approach
  would be to somehow create partitions and then different processes could 
  reside in different partitions.
请注意,这一段在分页概念之前,讨论的是立即分配给整个进程的内存。 我的问题是:

   Why should we create partitions? We can just keep track of holes in the memory 
   and keep pointers to the beginning and end of the holes. When we allocate a
   process some memory, we can associate the pointer to the beginning and end of 
   the process with the process and end pointer of the process serves as the 
   pointer to the beginning of a new hole. 
我想答案是“效率”。如果只想跟踪孔,最坏的情况是在给定内存块中有相当于字节一半的孔数(内存块中的每秒钟字节都是“孔”),这意味着对于给定大小的每个内存块,您需要额外的指针数,等于块大小的一半,例如:

区块大小:1024B

“孔”的最大数量:1024/2=512

指向磁道的单个“孔”的每个指针都是4B(在32位体系结构上),所以:512*4=2048B! 我希望我不必让你相信这不是最好的解决方案。一些聪明的人发现,要“解决”这个问题,你需要更大的内存“粒度”。换句话说,操作系统只分配固定大小的内存块(称为页面)。通常一页是4KB(4096B)。你可以这样想:当我们谈论内存分配时,操作系统不是零售商。操作系统只在页面中分配内存。在流程级别上需要更小的分配粒度-C库的实现在那里发挥作用(C库分配例程是零售商),例如:
malloc
free
函数和朋友。这些函数从操作系统中分配内存(以页为单位),然后跟踪“已使用”和“未使用”的块(这只是一个简化:比这复杂得多,它们根据请求的块的大小有不同的“策略”)

附言。
我知道这是非常笼统的,但我不知道您目前在这方面的知识有多广泛。

@sirgeorge…请注意,我指的是进程的连续内存分配。所以,如果每秒钟一个字节都是一个洞,这意味着每个进程都有一个字节长。我想我们可以同意,如果一个分区中遗漏了一个洞,那么另一个进程可以完全或部分地占用这个洞。例如:如果有一个256字节的分区,其中有一个100字节的进程。现在,如果出现一个50字节的进程,它可以占据100字节附近的一个位置(因此我们需要一个指针告诉我们100字节进程的结束)。那么,当指针可以处理它时,为什么还要涉及分区呢?