Microsoft KB Archive/68164

= CLOSE Doesn't Release Far Heap Used by First OPEN &quot;COM&quot; Buffer =

Article ID: 68164

Article Last Modified on 11/21/2006



This article was previously published under Q68164



SUMMARY
When you use the OPEN &quot;COMn:&quot; statement, the far heap memory allocated for the communications receive and transmit buffers is not deallocated when the file is closed. However, this communications memory area allocated in the far heap is reused if the COM port is reopened. [Far heap memory usage is indicated by the FRE(-1) function.]

Note that the file's memory overhead portion consumed in DGROUP (the default data segment) is completely released by the CLOSE statement. [DGROUP memory is reported by the FRE(&quot;&quot;) function in QuickBasic 4.x and in Basic Compiler 6.00/6.00b, but reported by the STACK function in Basic PDS 7.00/7.10.]

This information applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50; to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS; and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS.



MORE INFORMATION
By default, the communications transmit and receive buffers are set at 512 bytes. The transmit and receive buffer sizes can be changed by parameters in the OPEN &quot;COMn:&quot; string. For example, TB2048 = Increases the transmit buffer size to 2048 bytes. RB2048 = Increases the receive buffer size to 2048 bytes. The following code example duplicates this far heap consumption behavior: PRINT &quot;Far Heap before open:&quot;; FRE(-1) OPEN &quot;COM1:9600,N,8,1,RB4096&quot; FOR RANDOM AS #1 PRINT &quot;Far Heap after open:&quot;; FRE(-1) CLOSE #1 PRINT &quot;Far Heap after close:&quot;; FRE(-1) The output from this program shows that after the OPEN statement, the far heap is correctly reduced by 4096 plus some additional memory needed to maintain a file. But after the CLOSE, only a few bytes (equal to the file overhead release in DGROUP memory) get reallocated to the far heap.

Additional query words: QuickBas BasicCom

Keywords: KB68164

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.