为什么我们需要数据分区 [英] Why do we need saparate data section

查看:97
本文介绍了为什么我们需要数据分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在各种c项目的代码中都观察到单独的数据部分.
我从未在代码中创建数据部分.

我很想知道在什么情况下应该考虑为数据创建单独的数据部分?

通过创建单独的数据节可以实现哪些优势?

预先感谢您的答复

I have been observed separate data sections in code of various c projects.
I have never created data section in my code.

I am curious to know in what circumstances we should think about creating separate data section for the data?

What advantages can be achieved by creating separate data sections?

Thanks in advance for your reply

推荐答案

更强大的程序.
通过将数据部分和代码部分分开,操作系统可以将代码部分标记为只读,同时仍然允许您修改数据部分中的数据.

使用此系统后,尝试写入代码部分只会导致异常,通常会导致程序被咀嚼并吐出.

如果您还具有对代码部分的完全写访问权限,那么您犯的任何错误(写到该错误)都可能导致各种令人讨厌的行为.

它还有助于防止执行自修改代码(这是多态计算机病毒的一个共同特征)(以极大增加某些超优化代码的复杂性为代价,这些代码也会对其进行修改以减少执行时间). ,即使是只读代码段也可以在运行时转换为读/写.


它还可以根据当前操作条件将数据放置在物理内存中适当的位置.
More robust programs.
By separating the data and code sections, the OS can mark the code section as read-only, while still letting you modify data in the data section.

With this system in place, an attempt to write to the code section merely results in an exception, often causing your program to be chewed up and spat out.

If you have full write-access to the code section as well, any mistake you make (writing to it) can lead to all sorts of nasty behaviour.

It also helps prevent the execution of self-modifying code - a common feature of polymorphic computer virii (at the expense of greatly increasing the complexity of some super-optimized code that would also modify itself to cut down on execution time) Though to be clear, even a read-only code section can be turned into read/write at run-time.


It also allows for data to be located in physical memory at a place that''s deemed appropriate, based on current operating conditions.


除了 enhzflep 答案,某些系统功能(例如PIC微控制器)哈佛体系结构 [
In addition to enhzflep answer, some systems feature (e.g. the PIC microcontrollers) Harvard architecture[^] where code and data are physically separated.


这篇关于为什么我们需要数据分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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