PDA

View Full Version : My program has gone crazy



siim
20-11-2003, 10:45 PM
I suspect a memory leak, I wonder if the following code might be responsible for this:


const
b: array[0..12] of Byte = (1, 2, 3, 4, 5, 6, 7,8,9,10,11,12);

procedure readData(var X);
var
M: array[0..1] of Integer absolute X;
begin
// only read from M no writing here
end;

procedure DoSmthing;
begin
readData(b[2]);
end;


I know that when b would be an ordinary array then everything would be okay, but b is a const. Can it cause a memory leak?

Siim

Harry Hunt
20-11-2003, 11:08 PM
the code you posted does not contain memory leaks that would be apparent to me. A static array can't really leak memory so the problem must be somewhere else but the code you posted is not enough to say where it is.
Also, can you elaborate on how exactly your program is acting crazy?

Useless Hacker
20-11-2003, 11:50 PM
const
b: array[0..12] of Byte = (1, 2, 3, 4, 5, 6, 7,8,9,10,11,12);

I don't know about a memory leak (perhaps you could post some more code?), however, do you realise you are initialising a 13-element array with only 12 elements?

(That "absolute" directive is a useful one, I don't remember seeing it before.)

siim
23-11-2003, 03:09 PM
The 12 elements was typo I made. There are too much code to post it here. But the program just throws EExternalException when I finish running an function:


function DoIt: Boolean;
begin

end;//<-throws an exception here


Siim

siim
23-11-2003, 03:13 PM
Delphi recognizes the following exception codes:

?¢_¬¢ STATUS_INTEGER_DIVIDE_BY_ZERO
?¢_¬¢ STATUS_ARRAY_BOUNDS_EXCEEDED
?¢_¬¢ STATUS_FLOAT_OVERFLOW
?¢_¬¢ STATUS_FLOAT_INEXACT_RESULT
?¢_¬¢ STATUS_FLOAT_INVALID_OPERATION
?¢_¬¢ STATUS_FLOAT_STACK_CHECK
?¢_¬¢ STATUS_FLOAT_DIVIDE_BY_ZERO
?¢_¬¢ STATUS_INTEGER_OVERFLOW
?¢_¬¢ STATUS_FLOAT_UNDERFLOW
?¢_¬¢ STATUS_FLOAT_DENORMAL_OPERAND
?¢_¬¢ STATUS_ACCESS_VIOLATION
?¢_¬¢ STATUS_PRIVILEGED_INSTRUCTION
?¢_¬¢ STATUS_CONTROL_C_EXIT
?¢_¬¢ STATUS_STACK_OVERFLOW

Any exception code that is not on the list above raises an EExternalException.

As a descendant of EExternal, EExternalException saves the Windows exception record (if there is one) in its ExceptionRecord data structure.

Paulius
23-11-2003, 06:09 PM
Just comment out the code little by little to find out what exactly causes this exception and post that.