在 C/C++ 或任何其他此类语言中将 & 符号应用于变量或数据类型时返回什么类型的地址?

What type of address returned on applying ampersand to a variable or a data type in C/C++ or in any other such language?(在 C/C++ 或任何其他此类语言中将 符号应用于变量或数据类型时返回什么类型的地址?)

本文介绍了在 C/C++ 或任何其他此类语言中将 & 符号应用于变量或数据类型时返回什么类型的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我在我的操作系统课上听说虚拟和物理内存概念的那一天起,这是一个非常基本的问题,令人难以置信.现在我知道在加载时和编译时,虚拟地址和逻辑地址绑定方案是相同的,但在执行时它们不同.

This is a very basic question boggling mind since the day I heard about the concept of virtual and physical memory concept in my OS class. Now I know that at load time and compile time , virtual address and logical adress binding scheme is same but at execution time they differ.

首先,为什么在编译和加载时生成虚拟地址是有益的,以及当我们应用 & 运算符获取变量地址、朴素数据类型、用户定义类型和函数定义地址时返回什么?

First of all why is it beneficial to generate virtual address at compile and load time and and what is returned when we apply the ampersand operator to get the address of a variable, naive datatypes , user-defined type and function definition addresses?

操作系统如何从虚拟地址精确映射到物理地址?这些问题是出于好奇,考虑到现代操作系统,我希望能得到一些好的和深刻的见解,早期操作系统的情况如何.我只是 C/C++ 特定的,因为我对其他语言不太了解.

And how does OS maps exactly from virtual to physical address when it does so? These questions are hust out from curiosity and I would love some good and deep insights considering modern day OS' , How was it in early days OS' .I am only C/C++ specific since I don't know much about other languages.

推荐答案

物理地址发生在硬件中,而不是软件中.操作系统内核中存在一个可能/偶然的异常.物理意味着它是系统总线和 RAM 芯片看到的地址.

Physical addresses occur in hardware, not software. A possible/occasional exception is in the operating system kernel. Physical means it's the address that the system bus and the RAM chips see.

物理地址不仅对软件无用,而且可能是一个安全问题.无需地址转换即可访问任何物理内存,并且知道其他进程的地址,将允许不受限制地访问机器.

Not only are physical addresses useless to software, but it could be a security issue. Being able to access any physical memory without address translation, and knowing the addresses of other processes, would allow unfettered access to the machine.

也就是说,较小的或嵌入式机器可能没有虚拟内存,并且一些较旧的操作系统确实允许共享库指定它们的最终物理内存位置.此类策略会损害安全性并且已过时.

That said, smaller or embedded machines might have no virtual memory, and some older operating systems did allow shared libraries to specify their final physical memory location. Such policies hurt security and are obsolete.

这篇关于在 C/C++ 或任何其他此类语言中将 & 符号应用于变量或数据类型时返回什么类型的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 C/C++ 或任何其他此类语言中将 & 符号应用于变量或数据类型时返回什么类型的地址?

基础教程推荐