A lot of people saw my post entitled "Need More Memory?", where i showed a simple way to get an extra 64KB of conventional RAM under Windows, without the use of external libraries. Lots of computers don't have EMS or XMS, and computers that run Windows XP won't run libraries that use them. So if you need more memory you have to look at the conventional RAM. This trick only works in a multitasking environment, because you have to run two programs at once. The first 10 lines of code I have posted here go in the first program, it sets up a 64KB chunk of RAM and reserves it for you to use in your main program, it also saves the segment information and exact plaement of the chunk, so that you don't interfere with other programs. This program has to be running the entire time that the main one is, otherwise that chunk of memory is no longer reserved.
$DYNAMIC DIM array%(32766) OPEN "mem.tmp" FOR RANDOM AS #1 s% = VARSEG(array) PUT #1,,s% p% = VARPRT(array) PUT #1,,p% CLOSE WHILE INKEY$ = "":WEND KILL "mem.tmp"
Everything below here has to go in your main program, there are a set of routines that use the 64KB chunk of RAM. With these routines the chunk of RAM is broken down into integers, but you can change them to use any number of bytes.
DECLARE SUB putarray (subscript%, num%) DECLARE FUNCTION array% (subscript%) DECLARE FUNCTION Dec2Bin$ (onenumber%) DECLARE FUNCTION Bin2Dec% (onenumber$)
DIM SHARED s%, p% OPEN "mem.tmp" FOR RANDOM AS #1 GET #1, , s% GET #1, , p% CLOSE DEF SEG = s%
FUNCTION array% (subscript%) place% = p% + (subscript% * 2) IF place% > 65534 THEN DEF SEG = s% + 1: place% = place% - 65534 a$ = Dec2Bin$(PEEK(place%)) a$ = a$ + Dec2Bin$(PEEK(place% + 1)) IF place% > 65534 THEN DEF SEG = s% array% = Bin2Dec%(a$) END FUNCTION
FUNCTION Bin2Dec% (number$) place = 65535 / 2 FOR a% = 1 TO 16 c$ = MID$(number$, a%, 1) IF c$ = "1" THEN num% = num% + place place = place / 2 NEXT Bin2Dec% = num% END FUNCTION
FUNCTION Dec2Bin$ (number%) btring$ = "" DO digit% = number% MOD 2 bstring$ = LTRIM$(RTRIM$(STR$(digit%))) + bstring$ number% = number% \ 2 LOOP WHILE decnumber% > 0 FOR a% = 0 TO 16 IF LEN(bstring$) = 16 THEN EXIT FOR bstring$ = "0" + bstring$ NEXT Dec2Bin$ = bstring$ END FUNCTION
REM $STATIC SUB putarray (subscript%, num%) place% = p% + (subscript% * 2) IF place% > 65534 THEN DEF SEG = s% + 1: place% = place% - 65534 POKE (place%), num% DEF SEG = s% END SUB