malloc不保证返回物理上连续的内存 [英] malloc does not guarantee returning physically contiguous memory

查看:70
本文介绍了malloc不保证返回物理上连续的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关虚拟内存的信息,结论如下:

I'm reading about virtual memory and my conclusions are the following:

malloc(size);

  1. malloc不保证返回物理上连续的内存.它保证返回实际上连续的内存.尤其是当尺寸>因为4KB是页面的大小,所以为4KB.(在Linux系统上).

我是对还是错?请解释.

Am I right or am I wrong? Please explain.

推荐答案

malloc不能保证返回物理上连续的内存

malloc does not guarantee returning physically contiguous memory

它保证返回几乎连续的内存

It guarantees returning virtually contiguous memory

尤其是当大小> 4KB时,这是正确的,因为4KB是页面的大小.(在Linux系统上).

Especially it is true when size > 4KB because 4KB is a size of page. ( On Linux systems).

成为连续内存并不意味着它也会进行页面对齐.分配的内存可以从堆中的任何地址开始.因此,无论哪种操作系统使用页面大小,都不会影响malloc的分配性质.

Being contiguous memory does not imply that it will also be page aligned. The allcated memory can start from any address in heap. So whatever OS uses the page size it does not affect the allocation nature of malloc.

这篇关于malloc不保证返回物理上连续的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆