[fpc-devel] porting from fpc to tp7
Daniël Mantione
daniel.mantione at freepascal.org
Sat Mar 24 11:35:24 CET 2007
Op Sat, 24 Mar 2007, schreef Evgeniy Ivanov:
> On Sat, 24 Mar 2007 13:05:54 +0300, Daniël Mantione
> <daniel.mantione at freepascal.org> wrote:
>
>
> > > 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;
>
> >
> > Why do you increase cur_size two times? At the end of the procedure
> > cur_size is larger than the buffer is.
> Ou, surely. But it is new bug. When I used tp there was'n second increase.
> Also buf_count value is 10 and I have tried to add only 5 elements. After
> second startup the problems have begun.
Well, all I can say is check your code securely. The basic idea is good,
so it is likely the implementation.
> > Further, you want to use move instead of a for loop, since in TP the
> > speed difference is even larger than in FP.
>
> Sorry, but I didn't understand what you ment exactly. You ment to use ptr_buf
> = P and then getmem(P) and for loop?
Instead of:
for i:=1 to cur_size do
buff_ptr^[i] := P^[i];
... do:
move(p^[1],buff_ptr^[1],(cur_size-1)*sizeof(p^);
Also, is your array really 1-based?
Daniël
More information about the fpc-devel
mailing list