<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 14/03/2013 09:47, Jonas Maebe wrote:<br>
</div>
<blockquote
cite="mid:B6736665-2302-4D79-8E5C-740F20CDB036@elis.ugent.be"
type="cite"><br>
<div>
<div>On 14 Mar 2013, at 01:48, Xiangrong Fang wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite"><span class="Apple-style-span"
style="border-collapse: separate; color: rgb(0, 0, 0);
font-family: Monaco; font-style: normal; font-variant:
normal; font-weight: normal; letter-spacing: normal;
line-height: normal; orphans: 2; text-align: -webkit-auto;
text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width:
0px; font-size: medium; "><span class="Apple-style-span"
style="font-family: monospace; ">The document said it is
"deprecated"? Also, I want this to be cross<br>
platform, not for unix only. The use case is:<br>
<br>
try<br>
buf := GetMemory(1024);<br>
size := 10240;<br>
stream.Read(buf^, size);<br>
except<br>
??<br>
end;<br>
</span></span></blockquote>
</div>
<br>
<div>That use case is a textbook example of why you should never
try to catch and handle access violations, except possibly if
you then warn the user that anything could happen if he
continues (including erasing all files on his hard drive, if
he's very unlucky).</div>
<div><br>
</div>
<div>An access violation often indicates that memory has been
corrupted. Catching the access violation does not undo the
memory corruption, it just informs you about this fact. If you
continue after catching the exception in the above program, you
will be working with corrupted memory, which means that the
behaviour of your program becomes completely unpredictable
afterwards.</div>
<div><br>
</div>
</blockquote>
@Xiangrong<br>
<br>
In fact (after I saw the screenshot, that indeed the alloc mem is
less than the read), there is a possibility that the above good does
NOT even crash. Yet it corrupts memory and the app will crash at a
random later point.<br>
<br>
If the 1024 bytes happen to be allocated in such way that they are
followed by other already alocated memory, then they can be accessed
without SigSegV.<br>
</body>
</html>