QB help with disk files?

 BBS: Inland Empire Archive
Date: 04-15-92 (09:36)             Number: 187
From: TOM HAMMOND                  Refer#: NONE
  To: DONALD SUTER                  Recvd: NO  
Subj: QB help with disk files?       Conf: (2) Quik_Bas
DS> OPEN the sixteenth file.  My autoexe.bat has FILES=50 BUFFERS=30.
DS>Shouldnt QB4.5 be able to open more than 15 files at one time?

RV>I've seen code on one of the echoes about using interrupt
RV>to go in and increase the maximum DOS file handles.  I'm
RV>interested too.  I'll look and see if I captured any code.

Donald:

I sent a reply to you a week or so ago, but it apparently got dumped
into the bit bucket somewhere along the line.  Hope you get this one.


  'From    : HOWARD MENCHER
  'To      : ALL                                    Date: 12/30/91 2:48p
  'Subject : Open mega files at once 2

  ' The following is a BASIC code example of the DOS interrupt necessary
  ' to access more than 20 DOS file handles:

  ' $INCLUDE: 'qb.bi'
  ' For BASIC PDS 7.00 include QBX.BI
  ' For QuickBASIC include QB.BI

  DEFINT A-Z

  DIM InRegs AS RegType, OutRegs AS RegType

  NrFiles = 40    '35 open files + 5 file handles for DOS I/O

  CLS

  ' --------------------------

  '  This section of code did NOT come from Howard Mencher, but DOES
  '  appear to be REQUIRED in order for you to open more than about
  '  28-29 files at one time.

  '  MUST deallocate some memory from the Far Heap

  ON ERROR GOTO ReAllocateFarHeap

  Allocate = 128  '128 bytes is good up to at least 80 open files

  HeapBefore& = SETMEM(0)   ' Get size of far heap
  IF HeapBefore& - SETMEM(-Allocate) >= Allocate THEN
    FarHeap& = SETMEM(-Allocate)
  ELSE
    PRINT "Insufficient Memory to de-allocate"
    END
  END IF

  ' --------------------------

  'Continuing with code from Howard Mencher

  InRegs.ax = &H6700         'SetFileHandles function

  ' Value in BX register must be odd in DOS 3.30; odd or even in later
  ' DOS versions; ranging from 21 to 255:
  InRegs.bx = NrFiles      'The number of files to open

  CALL Interrupt(&H21, InRegs, OutRegs)

  FOR I% = 1 TO NrFiles - 5   '5 files are reserved for
                              '  DOS standard I/O.
    File$ = "Junk" + STR$(I%)
    OPEN File$ FOR OUTPUT AS I%
    PRINT I%
  NEXT
  CLOSE

' --------------------------

  ' This code did NOT come from Howard Mencher.  It just serves to
  ' verify 'that the deallocated memory is successfully returned to
  ' the Far Heap.

ReAllocateFarHeap:
  FarHeap& = SETMEM(Allocate + 128) 'Return AT LEAST as much memory
  HeapAfter& = SETMEM(0)            '  as was deallocated
  PRINT "Before:";   HeapBefore&
  PRINT " After:"; HeapAfter&
  IF HeapAfter& < HeapBefore& THEN PRINT "Far Heap Memory NOT returned"
  END

--------------- CUT HERE ---------------

When I imported this file into SLMR, it wrapped pretty badly.  I think
I was able to get it reformatted correctly.  Hope so anyway.

Hope this helps.  Good Luck.

Tom Hammond      N0SS
---
 þ SLMR 2.1 þ Press any key to continue or any other key to quit


--- WM v2.00/91-0231
 * Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET