[fpc-pascal] How can I implement "thrice" in Free Pascal?

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Oct 18 21:30:23 CEST 2011


On 18 Oct 2011, at 20:03, Andrew Pennebaker wrote:

> In particular, if anyone knows a way to implement a general concatenation
> function Concat(Arr1, Arr2), let me know.

I'm under the impression that you are trying to program in a statically typed language the same way as you'd use a dynamically typed language. Even with generic functions (which, as mentioned before, are not yet supported by FPC) you'd have to explicitly instantiate such a function for every type you'd want to do this for.

More generally, concatenating arrays is an operation that is seldom done, because
a) it's slow, especially once the arrays get to a certain size (lots of data copying, memory allocation operations)
b) it leads to memory fragmentation (freeing the old arrays, allocating a new one)

Pascal has a separate string type to optimize one common case where concatenating arrays is often required. In other cases, people generally use some form of list structure (generic or not) in case lots of insertions/deletions/concatenations are required.


Jonas


More information about the fpc-pascal mailing list