设置一个边界保护阵列 [英] Setting up a bounds-protected array

查看:108
本文介绍了设置一个边界保护阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分配一个数组,其设置使得之前和它是由存储器管理单元,所以企图在阵列的边界将被自动捕获运行保护后的网页;然后抓住它以处理错误在受控制的方式。

I'd like to allocate an array and set it up such that the pages before and after it are protected by the memory management unit, so an attempt to run over the bounds of the array will be automatically caught; and then catch it in order to handle the error in a controlled fashion.

我怀疑会有一个便携式解决方案,但什么是Windows和海湾合作委员会在Linux上使用Microsoft C中的最佳平台,具体方法分别?

I doubt there will be a portable solution, but what's the best platform specific method using Microsoft C on Windows and GCC on Linux respectively?

推荐答案

其实,有检测软件的内存分配超过了一个可移植的方式。 Dmalloc 提供栅栏柱覆盖检测

Actually, there is a portable way to detect memory allocation overruns in software. Dmalloc provides fencepost overwrite detection

栅栏后的内存区域正上方或下方内存
  分配。这是太容易写code以上或访问
  分配如下 - 尤其是数组或字符串的时候。
  这个库可以在区域编写特殊值周围的每一个
  分配所以它会注意到,当这些地区已被覆盖。

Fence-post memory is the area immediately above or below memory allocations. It is all too easy to write code that accesses above or below an allocation - especially when dealing with arrays or strings. The library can write special values in the areas around every allocation so it will notice when these areas have been overwritten.

http://dmalloc.com/docs/latest/online/dmalloc_17。 HTML#SEC22

这篇关于设置一个边界保护阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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