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

查看:36
本文介绍了为什么未初始化的指针会导致内存访问冲突接近 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:

当内存地址ZZZZZZZZZ接近于零时,原因往往是已被访问的未初始化指针.

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?

推荐答案

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

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).

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

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.

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

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