c内存管理和c++内存管理_内存管理简介

c内存管理和c++内存管理

Main Memory refers to a physical memory that is the internal memory to the computer. The word main is used to distinguish it from external mass storage devices such as disk drives. Main memory is also known as RAM. The computer is able to change only data that is in main memory. Therefore, every program we execute and every file we access must be copied from a storage device into main memory.

主内存是指物理内存,它是计算机的内部内存。 “ main”一词用于将其与外部大容量存储设备(例如磁盘驱动器)区分开。 主存储器也称为RAM。 计算机只能更改主内存中的数据。 因此,我们执行的每个程序和访问的每个文件都必须从存储设备复制到主存储器中。

All the programs are loaded in the main memeory for execution. Sometimes complete program is loaded into the memory, but some times a certain part or routine of the program is loaded into the main memory only when it is called by the program, this mechanism is called Dynamic Loading, this enhance the performance.

所有程序都加载到主存储器中以执行。 有时,完整的程序会被加载到内存中,但是有时程序的某个部分或例程只有在被程序调用时才会被加载到主内存中,这种机制称为动态加载 ,这可以提高性能。

Also, at times one program is dependent on some other program. In such a case, rather than loading all the dependent programs, CPU links the dependent programs to the main executing program when its required. This mechanism is known as Dynamic Linking.

同样,有时一个程序依赖于其他程序。 在这种情况下,CPU不需要加载所有从属程序,而是在需要时将从属程序链接到主执行程序。 这种机制称为动态链接

交换 (Swapping)

A process needs to be in memory for execution. But sometimes there is not enough main memory to hold all the currently active processes in a timesharing system. So, excess process are kept on disk and brought in to run dynamically. Swapping is the process of bringing in each process in main memory, running it for a while and then putting it back to the disk.

进程需要在内存中才能执行。 但是有时主内存不足,无法容纳分时系统中所有当前活动的进程。 因此,多余的进程将保留在磁盘上并使其动态运行。 交换是将每个进程放入主内存中,运行一段时间后再将其放回磁盘的过程。

连续内存分配 (Contiguous Memory Allocation)

In contiguous memory allocation each process is contained in a single contiguous block of memory. Memory is divided into several fixed size partitions. Each partition contains exactly one process. When a partition is free, a process is selected from the input queue and loaded into it. The free blocks of memory are known as holes. The set of holes is searched to determine which hole is best to allocate.

在连续内存分配中,每个进程都包含在单个连续内存块中。 内存分为几个固定大小的分区。 每个分区仅包含一个进程。 当分区空闲时,将从输入队列中选择一个进程并将其加载到其中。 空闲的内存块称为空洞 。 搜索Kong组以确定最佳分配哪个Kong。

记忆保护 (Memory Protection)

Memory protection is a phenomenon by which we control memory access rights on a computer. The main aim of it is to prevent a process from accessing memory that has not been allocated to it. Hence prevents a bug within a process from affecting other processes, or the operating system itself, and instead results in a segmentation fault or storage violation exception being sent to the disturbing process, generally killing of process.

内存保护是一种现象,通过这种现象我们可以控制计算机上的内存访问权限。 它的主要目的是防止进程访问尚未分配给它的内存。 因此,可以防止进程中的错误影响其他进程或操作系统本身,而导致将分段错误或存储违规异常发送到令人烦恼的进程,通常会杀死进程。

内存分配 (Memory Allocation)

Memory allocation is a process by which computer programs are assigned memory or space. It is of three types :

内存分配是一个为计算机程序分配内存或空间的过程。 它分为三种类型:

  1. First Fit:

    首先适合:

    The first hole that is big enough is allocated to program.

    足够大的第一个Kong分配给程序。

  2. Best Fit:

    最合适:

    The smallest hole that is big enough is allocated to program.

    足够大的最小Kong分配给程序。

  3. Worst Fit:

    最差的拟合度:

    The largest hole that is big enough is allocated to program.

    足够大的最大Kong分配给程序。

碎片化 (Fragmentation)

Fragmentation occurs in a dynamic memory allocation system when most of the free blocks are too small to satisfy any request. It is generally termed as inability to use the available memory.

当大多数可用块太小而无法满足任何请求时,就会在动态内存分配系统中发生碎片。 通常称为无法使用可用内存。

In such situation processes are loaded and removed from the memory. As a result of this, free holes exists to satisfy a request but is non contiguous i.e. the memory is fragmented into large no. Of small holes. This phenomenon is known as External Fragmentation.

在这种情况下,进程将被加载并从内存中删除。 结果,存在空洞来满足请求,但是空洞是不连续的,即存储器被分成大号。 小Kong。 这种现象称为外部碎片。

Also, at times the physical memory is broken into fixed size blocks and memory is allocated in unit of block sizes. The memory allocated to a space may be slightly larger than the requested memory. The difference between allocated and required memory is known as Internal fragmentation i.e. the memory that is internal to a partition but is of no use.

此外,有时物理内存会分成固定大小的块,并且会以块大小为单位分配内存。 分配给空间的内存可能比请求的内存稍大。 分配的内存和所需的内存之间的差异称为内部碎片,即分区内部的内存,但没有用。

分页 (Paging)

A solution to fragmentation problem is Paging. Paging is a memory management mechanism that allows the physical address space of a process to be non-contagious. Here physical memory is divided into blocks of equal size called Pages. The pages belonging to a certain process are loaded into available memory frames.

分页问题的解决方案是分页。 分页是一种内存管理机制,它允许进程的物理地址空间不具有传染性。 在这里,物理内存被分为大小相等的块,称为Pages 。 属于某个进程的页面被加载到可用的内存帧中。

页表 (Page Table)

A Page Table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual address and physical addresses.

页表是计算机操作系统中的虚拟内存系统用来存储虚拟地址物理地址之间的映射的数据结构

Virtual address is also known as Logical address and is generated by the CPU. While Physical address is the address that actually exists on memory.

虚拟地址也称为逻辑地址,由CPU生成。 而物理地址是内存中实际存在的地址。

分割 (Segmentation)

Segmentation is another memory management scheme that supports the user-view of memory. Segmentation allows breaking of the virtual address space of a single process into segments that may be placed in non-contiguous areas of physical memory.

分段是支持内存用户视图的另一种内存管理方案。 分段允许将单个进程的虚拟地址空间划分为多个分段,这些分段可以放置在物理内存的非连续区域中。

使用分页进行细分 (Segmentation with Paging)

Both paging and segmentation have their advantages and disadvantages, it is better to combine these two schemes to improve on each. The combined scheme is known as 'Page the Elements'. Each segment in this scheme is divided into pages and each segment is maintained in a page table. So the logical address is divided into following 3 parts :

分页和分段都有其优点和缺点,最好将这两种方案结合起来进行改进。 组合方案称为“分页”。 此方案中的每个段都分为多个页面,每个段都保存在一个页面表中。 因此,逻辑地址分为以下三个部分:

  • Segment numbers(S)

    段号(S)

  • Page number (P)

    页码(P)

  • The displacement or offset number (D)

    位移或偏移量(D)

翻译自: https://www.studytonight.com/operating-system/memory-management

c内存管理和c++内存管理

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值