问题描述
据我所知,字符串存储在只读存储器中的C语言的情况下。
这是哪里实际上美元的硬件p $ psent。
AFAIK, string literals are stored in read only memory in case of C language.where is this actually present on the hardware.
根据我所知堆是RAM.correct我,如果我错了。
as per my knowledge heap is on RAM.correct me if i am wrong.
如何从不同的只读内存是堆?
how different is heap from read only memory?
是取决于操作系统?
推荐答案
它通常与硬件辅助完成。
It is usually done with hardware assistance.
硬件的虚拟内存子系统可以告诉标记页面为只读。当应用程序试图写一个只读页面,硬件生成故障的操作系统捕获。操作系统可以告诉应用程序试图写一个只读页面并结束程序。
The virtual memory subsystem of the hardware can be told to mark a page as read-only. When an application tries to write a read-only page, the hardware generates a fault that the OS catches. The OS can tell that the app tried to write a read-only page and end your program.
因此,OS /加载程序确保字符串文字在被标记为只读的页面。
So the OS/loader makes sure the pages the string literals are in are marked as read-only.
堆和只读存储器是正交的问题。
The heap and read-only memory are orthogonal issues.
这篇关于只读存储器和堆存储器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!