Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-05

Customer Done procedure for dynamic arrays

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Brunner

I use dynamic arrays for data structures and sometimes types.

Under linux I have had no problems with transversing the list of data and calling "Done" on all types then calling finalize on the list itself.

Under windows I just executed the same code that worked under linux but crashed under windows.

TInt64Array=Array of Int64;
procedure Done(var List:TInt64Array);
begin
  Finalize(List);
end;
procedure Empty(var List:TInt64Array);
begin
  SetLength(List,0);
end;

In the above case the two procedures worked under linux. Under Windows Done crashes. Is this a bug that needs to be reported or is the memory manager performing different under Linux than under Windows.

This is a basic example. Some of my data structures involve strings and sub-arrays to other data structures or pointers thereto. To fix the problem I just use Empty instead of Done but I am looking to find out why can use Finalize on Linux but not on Windows?

Reply by email

Marc Weustink
to Andrew Brunner
Andrew Brunner wrote 30 lines
I use dynamic arrays for data structures and sometimes types. Under linux I have had no problems with transversing the list of data and calling "Done" on all types then calling finalize on the list itself. Under windows I just executed the same code that worked under linux but crashed under windows. TInt64Array=Array of Int64; procedure Done(var List:TInt64Array); begin Finalize(List); end; procedure Empty(var List:TInt64Array); begin SetLength(List,0); end; In the above case the two procedures worked under linux. Under Windows Done crashes. Is this a bug that needs to be reported or is the memory manager performing different under Linux than under Windows. This is a basic example. Some of my data structures involve strings and sub-arrays to other data structures or pointers thereto. To fix the problem I just use Empty instead of Done but I am looking to find out why can use Finalize on Linux but not on Windows?

Why do you want to finalize it ? This is automatically done by fpc when you set the length to 0 (or when the array goes out of scope)

Marc

Reply by email

Jonas Maebe
to Andrew Brunner: I use dynamic arrays for data structures and sometimes types. Under linux I have had no…
Andrew Brunner wrote 19 lines
Under windows I just executed the same code that worked under linux but crashed under windows. TInt64Array=Array of Int64; procedure Done(var List:TInt64Array); begin Finalize(List); end; procedure Empty(var List:TInt64Array); begin SetLength(List,0); end; In the above case the two procedures worked under linux. Under Windows Done crashes. Is this a bug that needs to be reported or is the memory manager performing different under Linux than under Windows.

Both should work and have the same effect, afaik. So please report a bug.

Jonas

Reply by email