[fpc-devel] porting from fpc to tp7

Evgeniy Ivanov lolkaantimat at gmail.com
Sat Mar 24 13:33:16 CET 2007


On Sat, 24 Mar 2007 13:35:24 +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.
I will try. May be there is some problem with index and memory in tp and  
dos (dos emulation in NT) is unsecure.



>> > 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^);

Thanks, I will try.

> Also, is your array really 1-based?

Hm... I didn't understand. I have such definitions of my array:

type dynamic_array = array[1..buf_count] of BusStation;  //BusStation is  
record with 4 strings
dynamic_array_ptr = ^dynamic_array;
var

list:dynamic_array_ptr;  // it's my "dynamic array" with its size counter
list_count:Integer;
...
// How I use it:
for i:=1 to num_of_strings do
   begin
   if i > list_count then
      add_mem(list,list_count);


I herd that there were problems with dos games: sometimes they started not  
 from the beginning, but from last time ending.

-- 
Best regards
E.I.



More information about the fpc-devel mailing list