Dec 222017
Quick Basic string routines to use all available memory.
File MWALLOC.ZIP from The Programmer’s Corner in
Category BASIC Language
Quick Basic string routines to use all available memory.
File Name File Size Zip Size Zip Type
COMPILE.BAT 338 225 deflated
FARESULT 6707 2031 deflated
MWALLOC.BAS 2480 1065 deflated
MWALLOC.DOC 3705 1744 deflated
TPCREAD.ME 199 165 deflated

Download File MWALLOC.ZIP Here

Contents of the MWALLOC.DOC file


by Mike Welch

Probably one of the least understood and therefore least used
features of QuickBASIC involves the ability to use all of available
memory with fixed length strings. This cannot be accomplished with
regular strings (i.e., string name is followed by $) but works fine
if you follow a few simple rules:

1. You should DIMension a fixed length string as in
a. DIM MyFixedLengthString(1 TO n) AS STRING * PowerOfTwo
b. PowerOfTwo *MUST* always be a number that is a
power of two, like 2,4,8,16,32,64,128,256,etc..
2. You must have the following in the top of your program:
3. You must compile with the /AH/O command line switch, as in:

While this method works, it is a bit more work determining how
much free memory is available for these "huge arrays." If you were using
an array that, say, was AS STRING * 64 (64 is a power of two) in length,
how many subscripts can you safely assign the array before you get an
"Out of Memory" error? Hopefully, MWALLOC.BAS will give you a place to
start. It only really works well with strings that are 64 bytes each in
length, but can be modified to work with other lengths. The nice thing
about MWALLOC is that it works no matter how much free RAM is actually
available (after all, can you expect that all of your users will have
the same amount of system memory? I expect not.).
I have included a file called FAResult (that's FAR Result) which
details the alpha testing of MWALLOC on my system when less and less
conventional RAM is available. At the end of FARESULT, you will see that
MWALLOC only allows *3* subscripts for the array because there is only
a few bytes of available RAM. The point of FARESULT is just to serve as
a sort of "proof" that, for huge arrays that are all 64 bytes in length,
MWALLOC does indeed provide save parameters in which to work.
I recently tested MWALLOC for strings that are AS STRING * 128
in length, and found that the 100 divisor should be changed to 150. In
this case, I found my arrays used about 480K (on my particular system
with my available RAM) for string space! I highly suggest that, if it
works in one run, it will work in any run since MWALLOC automatically
adjusts the amount of subscripts depending on available memory. I
therefore suggest that 150 is a fine divisor to use for strings that
are 128 bytes in length. Other values can be obtained for other array
lengths, just be sure to test it first!
The following tables give you a formula for a few other values
that I have tested. Since MWALLOC is a short program that is dedicated
only to processing this test, I would suggest testing your program and
making adjustments on the FreeMem& \ n statement as necessary. As it
stands, though, I have found the following values to work with MWALLOC:

1. For AS STRING * 128, use X = FreeMem& \ 150
a. Note: This value (150) could probably be less
2. For AS STRING * 64, use X = FreeMem& \ 100
a. Note: MWALLOC.BAS is using this amount as example
3. For AS STRING * 32, use X = FreeMem& \ 50
a. I optimized this one to the max, I think
4. For AS STRING * [less than 32: 8,4,2]:
a. I do not suggest going below X = FreeMem& \ 25

QuickBASIC is NOT the ONLY language in which to program, it's
not the best language for all purposes, but it is a very powerful language
in its own right and should command the respect it deserves. BASIC isn't
just a beginner's language anymore...hopefully, some day this fact will
be realized by more of the professional community.

 December 22, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>