Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-02

memw

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Mills

Hi,

This is from an old Turbo Pascal source of the Pascal S compiler source:

          getmem(spnt,((sleng+3) div 16 +1)*16);
          k := seg(spnt^);
          memw[k:0] := sleng;
          memw[k:2] := 0;
          move(sbuff[1],mem[k:4],sleng);

How would you convert that into FPC syntax for linux ?

cheers
James

Reply by email

Marco van de Voort
to Anton Tichawa: Hi, James! just a first approach by heart - i neither tested it, nor did i check the…

[ Charset ISO-8859-1 unsupported, converting... ]

Show quoted text 31 lines
Hi, James! On Sunday 23 February 2003 18:44, you wrote: > This is from an old Turbo Pascal source of the Pascal S compiler source: > > getmem(spnt,((sleng+3) div 16 +1)*16); > k := seg(spnt^); > memw[k:0] := sleng; > memw[k:2] := 0; > move(sbuff[1],mem[k:4],sleng); > > How would you convert that into FPC syntax for linux ? just a first approach by heart - i neither tested it, nor did i check the syntax. if you need explanation or testing, i can do that. but maybe it works at once: type p_words = ^ t_words; t_words = array [0 .. maxint] of word; var spnt: p_words; begin getmem(spnt,((sleng+3) div 16 +1)*16); ? spnt ^ [0] := sleng; ? spnt ^ [1] := 0; ? move(sbuff[1], @(spnt ^ [2]),sleng); end.

This is correct. I think, but probably the size passed to getmem is also special. All the calculation is only to make sure that memory is allocated in pieces of 16 bytes. (a segment), but that doesn't matter much anymore.

So that probably can change to simple

getmem (spnt,sleng+3);
if that is the size needed.

Better, the entire stuff could simply change to use a pointer to an array of record (with two fields in it). It might be a workaround to TP's 64k limit that FPC doesn't have. (or do you heapalloc for that?)

Also be careful with this kind of code if it stores pointers, because pointers are 32-bit now!

Reply by email

Anton Tichawa
to James Mills: This is from an old Turbo Pascal source of the Pascal S compiler source:…

Hi, James!

you wrote 9 lines
This is from an old Turbo Pascal source of the Pascal S compiler source: getmem(spnt,((sleng+3) div 16 +1)*16); k := seg(spnt^); memw[k:0] := sleng; memw[k:2] := 0; move(sbuff[1],mem[k:4],sleng); How would you convert that into FPC syntax for linux ?

just a first approach by heart - i neither tested it, nor did i check the syntax. if you need explanation or testing, i can do that. but maybe it works at once:

type
  p_words = ^ t_words;
  t_words = array [0 .. maxint] of word;
var
  spnt: p_words;
begin
  getmem(spnt,((sleng+3) div 16 +1)*16);
  spnt ^ [0] := sleng;
  spnt ^ [1] := 0;
  move(sbuff[1], @(spnt ^ [2]),sleng);
end.

----------

"Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben."

Doris Langley Moore: Ada, Countess of Lovelace (London 1977).

----------

Anton Tichawa
Volkertstrasse 19 / 20
A-1020 Wien
mobil: +43 664 52 07 907
email:

----------

Reply by email