[fpc-devel] porting from fpc to tp7

Daniël Mantione daniel.mantione at freepascal.org
Sat Mar 24 11:05:54 CET 2007



Op Sat, 24 Mar 2007, schreef Evgeniy Ivanov:

> Hi! I'm doing my tasks with fpc in linux, but in the university we have only
> tp, and there are several problems with bringing binaries.

You have some negotiations to do :)

> I have such code to have something like dynamic arrays:
> 
> procedure add_mem(var P: dynamic_array_ptr; var cur_size:Integer);
> var
> i:Integer;
> buff_ptr:dynamic_array_ptr;
> begin
> getmem(buff_ptr,cur_size*sizeof(BusStation) );
> for i:=1 to cur_size do
> buff_ptr^[i] := P^[i];
> freemem(P);
> cur_size:=cur_size+buf_count;
> getmem(P,cur_size*sizeof(BusStation) );
> for i:=1 to (cur_size-buf_count) do
> P^[i] := buff_ptr^[i];
> freemem(buff_ptr);
> cur_size:=cur_size+buf_count;
> end;
> 
> In fpc it works. But in tp my programme sometimes starts from last time and
> have a part of last data and some garbage (not text). Why does it work in fpc,
> but doesn't in tp? I see the only way to rewrite code, but I want to know why.

Why do you increase cur_size two times? At the end of the procedure 
cur_size is larger than the buffer is.

Further, you want to use move instead of a for loop, since in TP the 
speed difference is even larger than in FP.

Daniël


More information about the fpc-devel mailing list