为什么未初始化的指针会导致mem访问冲突接近于0? [英] Why uninitialized pointers cause mem access violations close to 0?

查看:78
本文介绍了为什么未初始化的指针会导致mem访问冲突接近于0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据说经常(但并非总是如此),当您在接近零的内存位置(例如$ 89)获得AV时,您有未初始化的指针。

但是我在Delphi的书中也看到了这一点……嗯……或者它们都是由同一位作者写的??

It is said that often (but not always) when you get an AV in a memory location close to zero (like $89) you have an uninitialized pointer.
But I have seen this also in Delphi books... Hm... or they have been all written by the same author(s)???

更新:

引用Bob Swart等人在 C ++ Builder 6开发人员指南中的引用,第71页:

Update:
Quote from "C++ builder 6 developers guide" by Bob Swart et all, page 71:


当内存地址ZZZZZZZZZZZ接近于零时,原因通常是
是已访问的未初始化指针。

When the memory address ZZZZZZZZZ is close to zero, the cause is often an uninitialized pointer that has been accessed.

为什么会这样?为什么未初始化的指针包含低数字?为什么不使用$ FFFFFFF这样的大数或普通随机数呢?这是都市神话吗?

Why is it so? Why uninitialized pointers contain low numbers? Why not big numbers like $FFFFFFF or plain random numbers? Is this urban myth?

推荐答案

这会使未初始化的指针与空引用或空指针混淆。对对象字段的访问或对指针的索引将表示为相对于基本指针的偏移量。如果该引用为null,则偏移量通常是接近零的地址(对于正偏移量)或接近本机指针大小的最大值的地址(对于负偏移量)。

This is confusing "uninitialized pointers" with null references or null pointers. Access to an object's fields, or indexes into a pointer, will be represented as an offset with respect to the base pointer. If that reference is null then the offsets will generally be addresses either near zero (for positive offsets) or addresses near the maximum value of the native pointer size (for negative offsets).

具有这些特征小值(或大值)的地址的访问冲突是您具有 空引用 空指针的一个很好的提示 em> ,而不仅仅是 未初始化的指针 。未初始化的引用可以具有空值,但也可以具有任何其他值,具体取决于分配方式。

Access violations at addresses with these characteristic small (or large) values are a good clue that you have a null reference or null pointer, specifically, and not simply an uninitialized pointer. An uninitialized reference can have a null value, but may also have any other value depending on how it is allocated.

这篇关于为什么未初始化的指针会导致mem访问冲突接近于0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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