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,777 of 2,978    |
|    P. Scott Harris to Jim Leonard    |
|    Re: Any way to limit memory usage of TP     |
|    15 Jun 05 14:41:16    |
   
   From: psharris.MAPS@magma.MAPS.ca   
      
   I've successfully allocated 64K chunks using both the heap and DOS   
   memory allocation. My guess is that you'll need to play with the $M   
   compiler setting. The following code works for me (DOS box, Windows XP)   
      
   {$A+,B-,D+,E-,F-,G+,I-,L+,N-,O-,P+,Q-,R-,S-,T+,V+,X+,Y+} {take off R+,S+}   
   {$M 16384,0,81920} { normally heap max = 655360 but leave space for 64K }   
      
   type   
    ptr_rec = record   
    offset : word ;   
    segment : word ;   
    end ;   
      
    PBlk32k = ^Tblk32k ;   
    TBlk32k = array[ 0..$7FFF ] of byte ;   
      
   var   
    block1,block2 : PBlk32k ;   
    block3 : word ;   
      
   Function Allocate( numpara : word) : word ; assembler;   
   asm   
    mov ah,$48   
    mov bx,numpara   
    inc bx   
    int $21   
    jnc @ok   
    mov ax,$0000   
    @ok:   
   end;   
      
   Function DeAllocate( mseg : word) : word ; assembler;   
   asm   
    mov ah,$49   
    mov es,mseg   
    int $21   
    jc @out   
    mov ax,0   
    @out:   
   end;   
      
   begin   
   { use heap to allocate 64K memory as 2 consecutive blocks }   
    New( block1 ) ;   
    if ( block1<>NIL ) then   
    begin   
    New( block2 ) ;   
    if ( block2<>NIL ) then   
    begin   
    { get at big array though pointer based from start of block1 }   
    Byte( Ptr( Ptr_rec( block1 ).segment,$FFFF )^ ) := $A5 ;   
    { notice that block2[$7FFF] now has $A5 in it }   
    end ;   
    end ;   
    Dispose( block2 ) ;   
    Dispose( block1 ) ;   
      
   { Use DOS allocate to accomplish the same thing }   
    block3 := Allocate( $10000 Div 16 ) ;   
    if ( block3<>0 ) then   
    begin   
    { as above,get at big array though pointer based on block3 }   
    Byte( Ptr( block3,$FFFF )^ ) := $A5 ;   
    DeAllocate( block3 ) ;   
    end ;   
   end .   
      
   Hope this helps.   
      
   P. Scott Harris   
   H&L Associates   
      
   Jim Leonard wrote:   
   > I'm writing a program that needs a full 64K segment of memory. Since   
   > TP's heap manager can only allocate a maximum of 65536-8 bytes, I avoid   
   > the TP heap manager and just call DOS to allocate the memory, then call   
   > DOS again to free it up.   
   >   
   > My problem is that I am running into a bug (in a different section of   
   > code) that I would love to use the IDE debugger on... but the IDE grabs   
   > all free RAM for itself, so when my program calls DOS to get some RAM,   
   > DOS reports (correctly) that there isn't a 64K free block to give me   
   > (since the IDE is taking everything).   
   >   
   > So, my questions:   
   >   
   > - Is there a way to limit the IDE's usage of RAM?   
   >   
   > - If not, is there a way to "trick" the heap manager into giving me two   
   > contiguous 32K blocks so that I can treat them like a single 64K block?   
   >   
   > Thanks in advance for any pointers (pun intended).   
   >   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca