malloc返回内存或虚拟地址空间 [英] malloc returns memory or virtual address space

查看:184
本文介绍了malloc返回内存或虚拟地址空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

malloc是在堆上分配一块内存吗?还是应该将其称为虚拟地址空间?

Does malloc allocate a block of memory on the heap or should it be called Virtual Address Space?

我是不是很挑剔,称其为虚拟地址空间,或者仅仅是DOS的遗留物? Linux怎么样?

Am I being picky calling it Virtual Address Space or this just the legacy of DOS? How about Linux?

许多详细的答案,但是没有一个回答我的问题.

many answers with great details, none of them answer my question, though.

推荐答案

要回答此问题,我们需要知道我们要处理哪种操作系统和体系结构.如前所述,标准和条款指的是存储"或空间".这些是最笼统且唯一有效的术语,除非我们做出一堆假设.

To answer this question, we need to know what kind of Operating System and architecture we are dealing with. As pmg mention the Standard and articles refers to "storage" or "space". These are the most general terms and the only valid ones, unless we make a bunch of assumptions.

例如:

malloc分配一个虚拟块 堆上的地址空间

malloc allocates a block of Virtual Address Space on the heap

对于许多嵌入式系统来说,这是不正确的.他们中的许多人不使用虚拟内存,因为没有必要(不需要多任务等)或出于性能原因.而且,某些奇特的设备可能没有堆的想法-怀疑会使用malloc,但是,这恰恰是标准引用存储"的原因之一-它是特定于实现的.

This is not correct for many embedded systems. Many of them do not use Virtual Memory, because there is no need (no multitasking etc.) or for performance reasons. What is more, it is possible that some exotic device does not have the idea of heap – doubt that malloc would be used, but fairly that is one of the reasons why the Standard refers to "storage" - it is implementation-specific.

另一方面,该示例对于我们PC中的Window和Linux是正确的.让我们对其进行分析以回答问题.

On the other hand, the example is correct for Window and Linux in our PCs. Let's analyze it to answer the question.

首先,我们需要定义什么是虚拟地址空间.

First off, we need to define what is Virtual Address Space.

虚拟地址空间(VAS)是一种内存映射机制,有助于管理多个进程.

Virtual Address Space (VAS) is a memory mapping mechanism that helps with managing multiple processes.

    隔离流程–每个流程都有 他自己的地址空间
  • 允许分配32位内存 建筑仅限于此.
  • 提供一种简洁的记忆模型
  • isolate processes – each of them has his own address space
  • allow to allocate memory that 32-bit architecture is limited to.
  • provides one concise model of memory

回到问题,"malloc是在堆上分配一块内存还是应该将其称为虚拟地址空间?"

Back to question, "Does malloc allocate a block of memory on the heap or should it be called Virtual Adress Space ?"

两个陈述都是正确的.我宁愿说VAP而不是内存-它更明确.有一个普遍的神话,即malloc = RAM内存.在过去,DOS内存分配非常简单.每当我们要求内存时,它总是RAM,但是在现代Oses中,它可能会有所不同.

Both statements are correct. I would rather say VAP instead of memory – it is more explicit. There is a common myth that malloc = RAM memory. Back in old day, DOS memory allocation was very simple. Whenever we ask for memory it was always RAM, but in modern Oses it may vary.

这篇关于malloc返回内存或虚拟地址空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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