Well, it is a Ham Radio log program, where the so-called DXCC-countries
are counted. There are 11 different 'bands', where the radio contact
takes place. There are some 333 countries actually, but very few have
collected so many. The array will be large, but in most cases quite
empty. To save memory a dynamic array is considered.
Procedure DxccCountries;
Var Data :array of array of string[3];
Band :integer; {bands 0..10}
Ctry :string[3]; {country number as string}
m,c :integer; {counters}
ok :boolean;
begin
initialize(data);
SetLength(Data,11); { [Data[0..10, ok }
c:=0;
While not (DbTable.EOF) do begin
Band:=DbTable.Fields[2].AsInteger; {a band, between 0..10}
Ctry:=DbTable.Fields[3].AsString;
ok:=true;
If Ctry<>'' then begin {sometimes Ctry not
saved}
SetLength(Data[2],c+1);
For m:=0 to c do begin
if Data[Band,m] = Ctry then ok:=false; {Ctry already
counted}
end;
If ok =true then begin
Data[Band,c]:=Ctry; {this is a new Ctry on this Band}
inc(c);
end;
DbTable.Next;
....
Finalize(Data);
It seems to function except that sometimes an array value is not empty
nor a string[3], but its length is 251 and it contains rubbish, because
the array is not initialized(?). I tried to use the Country number also
as an integer but to no avail.
I could not create the SetLength(Data,i,j) -rectangular method to
function correctly. Another point is, do we save much memory in using
the dynamic array?
-Rob
"Robert Ankka" <robert...@hot---mail.com.invalid> wrote in message
news:9r7eqt$4b5$1...@nyytiset.pp.htv.fi...
As in this program it is question of short strings, no initialization is
needed? But how to prevent the array variable containing some 351
characters of rubbish?
How should the Finalize be used in the example I gave?
-Rob
How to use it to free the memory of data1, data2?
As I could not do it I used instead
SetLength(data1,0,0);
SetLength(data2,0,0);
at the end of the program, which seems to empty the huge arrays nicely.
-Rob
At the end of your program, all memory will be freed by
the OS anyway.
Those arrays are, for lack of a better word, static.
The variables referencing them aren't pointers and
you shouldn't free the memory from under them. If
you want dynamic memory allocation, that's fine -
but don't start by putting variables on the stack.
Groetjes,
Maarten Wiltink