[fpc-pascal]FPC 1.0.6 and open arrays

cribeiro at mail.inet.com.br cribeiro at mail.inet.com.br
Sat Jan 25 14:57:43 CET 2003


Although I've not been using FPC for some time now (just following the
list), I think I can answer your question.

You can't declare an open array variable direcly in Pascal. The reason is
memory allocation. Standard Pascal types - for example, integers and
arrays - are allocated statically by the compiler. This means that the
compiler has to know how much memory to allocate. Pointers and classes are
dynamic types are allocated at runtime, and can be more flexible in this
respect, but this does not directly solve your problem.

You need to be careful also when using open arrays as parameters. Open
arrays are supported as parameters passed by reference only, because in
this situation the compiler does not care about the structure size - only
a pointer is passed. But this still has a strong limitation - you can't
change the size of the array at runtime, unless you are willing to mess up
with memory allocation yourself.

What solutions are available? There are a few directions you can go. The
RTL has a collection class that can solve your problem, but the
performance may suffer a little bit in some cases because of the overhead
involved. If you need a high performance solution for simple arrays (for
example, for number crunching), you can declare your arrays dinamically,
but beware - you'll have to write your own memory management routines, and
this is already implemented in the collection library.

Carlos Ribeiro

> Hi All,
> Does FPC support open arrays?
> I get an error compiling something like this:
> type
>   m = array of integer;
> but it works fine if I declare it inside a procedure or a function:
> procedure OpenArray(var m: array of integer);
> Thanks!
> --
> Jilani Khaldi
> http://www.jilani.net
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list