Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.pascal.borland    |    Borland Pascal was actually pretty neat    |    2,978 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 1,778 of 2,978    |
|    =?ISO-8859-1?Q?Bj=F6rn_Felten?= to All    |
|    Re: Any way to limit memory usage of TP     |
|    15 Jun 05 21:25:42    |
   
   From: abuse@telia.com   
      
   > Is it *guaranteed* that Turbo Pascal 7 allocates memory blocks   
   > contiguously?   
      
    Unfortunately not. So you'd better add some code to check the   
   integrity of your memory space. For what it's worth, below you have my   
   unit for allocating contiguous heap space. At the bottom there's a small   
   test program for the unit.   
      
      
   {$G+} (* It even needs a 386 or better... *)   
   unit LArrUnit;   
   (* A unit to handle large arrays in TurboPascal   
    By Björn Felten @ 2:203/208, 1991, 1994 *)   
      
   interface   
      
   const ArrSize = 100000;   
      
   type ArrItem = longint;   
    ItemPtr = ^ArrItem;   
      
   function BigArray(ItemNo:longint):ItemPtr;   
      
   implementation   
      
   const ItemSize = sizeof(ArrItem);   
      
   var AddressBase:record   
    P:ItemPtr;   
    Size:longint   
    end;   
      
   procedure Error(S:string; N:word);   
   begin writeln(S); halt(N) end;   
      
   function BigArray;assembler;   
   asm   
   db $66; mov ax,word ptr ItemNo   
   db $66; xor cx,cx   
    mov cx,ItemSize   
   db $66; mul cx   
    mov cx,ax   
   db $66; shr ax,4   
    les dx,AddressBase.P   
    mov bx,es   
    add ax,bx   
    and cx,15   
    add dx,cx   
    xchg ax,dx   
   end;   
      
   function InitArray(NumItems:longint):integer;   
   var TotalSize:longint;   
    Num32KSeg,SegCounter:word;   
    Dummy,LastCheckPtr:pointer;   
   begin   
    TotalSize:=NumItems*sizeof(ArrItem); (* Number of bytes required *)   
    if MaxAvail
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca