Page 1 of 1

MEMORY OVERFLOW ERROR !!! (Don't need help anymore)

Posted: Sun Apr 27, 2008 2:19 pm
by TmEE
I've got them before actually, but managed to get rid of them by moving some code to SUBs (I think I hit the 64k code per SUB limit).
Now I got it again, so I moved more code to SUBs, and the error remains... I can run it in IDE, but not compile...

Source file is 68.6KB big, consists of almost 3000 lines of code, lots logic operations and direct I/O...

any ideas ?

Posted: Sun Apr 27, 2008 9:01 pm
by Mentat
Try to keep data in separate files and the processes to the executable itself.

If you are in real need of compression, with some fancy tricks, you can save multiple flags to a variable.

Posted: Sun Apr 27, 2008 9:12 pm
by TmEE
I have nearly no data in the file, its all code... there's not much variables either... maybe half a KB. There's array's, but they all are less than 5...6KB. I also use 512KB of XMS but that doesn't matter...

I think I'm having too much code...

Code: Select all

COMMON SHARED HANDLE%, MBASE%, speed%, SCOUNT%, QUIT%, TMFROW%, ORDERROW%
COMMON SHARED TMFLEN%, TMFPAT%, EXITS%, PAGE%, MX%, MY%, MB%, COCTAVE%
COMMON SHARED KEYS%, TRACKPOS%, SAC%, PLAYMOD%, SEGM%, OFFSET&, OFFSET2&
COMMON SHARED Title$, Author$, Notes$, TMFdate$, CURPOS%, LASTCUR%, Ch1%
COMMON SHARED NOOT%, OKTAV%, OCTPLUS%, NOTE%, octave%, EFFECT%, VALUE%
COMMON SHARED EDITCH%, LCPOS%, CPOS%, DRUM%, i%, L%, C%, C2%, START%, ISPEED%
COMMON SHARED OFFS%, XOFF&, BYTES&, ERRR%, LASTCUR2%, CURPOS2%, EDITPOS%
COMMON SHARED ZSEG%, XSEG%, CDIR$, TMFfileName$, UPDATEPOS%, COPYSTART%
COMMON SHARED COPYLEN%, SHIFTON%, COPYCH%, COPYS%, COPYPASTELEN%, ERR2%
COMMON SHARED PLAYINLOOP%, LOOPVAL%, CHAN%, CTRL%, PATCH%, SPD%, DIR%
COMMON SHARED SHIFTSTART%, SHIFTEND%, LOOPORDER%, ECH%, EDITENABLE%, OFFSETP&

DIM SHARED Patterns&(63, 7)    'Current pattern, rest is in XMS
DIM SHARED OrderTable%(255, 6) 'Order table
DIM SHARED CopyPaste&(63)      'CopyPaste buffer
DIM SHARED Transpose&(63)      'Transposing buffer
DIM SHARED Patches%(8)         'Current instruments
DIM SHARED NoteVols%(8)        'Current volumes
DIM SHARED NotePans%(8)        'Current pan positions
DIM SHARED NoteRevs%(4)        'Current reverb amounts
DIM SHARED SPatches%(4)        'Start-up instruments
DIM SHARED SNoteVols%(8)       'Start-up volumes
DIM SHARED SNotePans%(4)       'Start-up pan positions
DIM SHARED SNoteRevs%(4)       'Start-up reverb amounts
DIM SHARED Instrument$(127)    'Instrument names
DIM SHARED Notes$(13)          'All notes that get displayed
DIM SHARED LastNote%(10)       'Last note played (for MIDI KEY OFF)
DIM SHARED HEXnum$(255)        'Hex numbers
DIM SHARED NumPt%(6)           'Number of patterns on each channel
DIM SHARED PSGnotes$(127)      'All PSG track notes
DIM SHARED PSGfreqs%(127)      'All PSG frequencies
DIM SHARED PSGvols$(16)        'All PSG volumes
DIM SHARED ChMutes%(8)         'Mute flags of all channels
DIM SHARED SlideCount%(4)      'Slide increment/decrement
DIM SHARED SlideFrame%(4)      'Slide frame count
DIM SHARED SlideFrames%(4)     'Slide frame counter
DIM SHARED SlidingDir%(4)      'Slide direction
DIM SHARED RandomPan%(4)       'Random panning
DIM SHARED DrumKeys%(127)      'Drum scancode to instrument table
And some bytes of data as DATA statements...

Posted: Mon Apr 28, 2008 6:58 am
by Mentat
That's a lot of DIM SHAREDs. A lot. Are you passing values through subroutines by reference?

Posted: Tue Apr 29, 2008 7:25 am
by TmEE
Routines need full access to the arrays/variables

Posted: Wed Apr 30, 2008 12:29 pm
by Ralph
The url below deals with "Program memory overflow" in qbx (PDS), as due to too many constants )over 680). Perhaps that is your problem?
http://support.microsoft.com/kb/61349

Also, this question is answered here:
http://www.outer-court.com/basic/echo/T37.HTM

In the second case, the error message refers to the program size in the interpreter as being under the 64K limit, but being too large for the object file. The solution is given in the second url, as to make two, smaller object files.

Posted: Wed Apr 30, 2008 1:57 pm
by TmEE
I have the second issue then... can't fit stuff to OBJs...

Now I need the command line switches and stuff of BC.EXE and LINK.EXE...

Posted: Wed Apr 30, 2008 3:48 pm
by Ralph
Exploring farther:

My QuickBASIC 4.5 Help/Modules/Modules and Procedures says that there can only be one main module, or "the main program". So, it would seem to me that you need to farther reduce your code, anyway you can, before you can create your object and compiled files.

Posted: Thu May 01, 2008 9:36 am
by TmEE
There is NO way to reduce the code... its already hyper space and speed optimized...

it seems I need to start digging FreeBASIC... any recommendations on getting started ?

Posted: Thu May 01, 2008 11:33 am
by BDZ
You don't need to start digging Freebasic. I would've posted in this topic earlier, but I figured someone would come along who could explain it better than me.

There is a 64k limit per module, so you need to split your program into 2 or more modules, compile them into object files seperately, then link them together. This sounds daunting, but I did it with my game awhile back and it wasn't too hard. The GUI makes it really easy to treat multiple modules like one. You can also have it so it automatically loads them in at the same time, and when you compile it links them for you. I don't have the time right now to explain exactly how you should do this, but this is the way to go.

Posted: Fri May 02, 2008 11:28 am
by TmEE
the thing is the main module doesn't even have 200 lines of code... and no other part exceeds the 64K limit, at least none has enough code to exceed it...

And I need to make a Windows version of my tracker anyway, so FB is the best option for that... first a pmode DOS version, then a Win version...

Posted: Sat May 24, 2008 11:05 pm
by Yazar
just divide your code into more modules. To do this, Open file menu, create file, and move your subs to there...

Posted: Sun May 25, 2008 7:39 am
by TmEE
well, it won't work... and I already have FB version in progress... damn MIDI, I've not got it to work in Win yet... I'll go for YM2612 emulation directly.

?????????

Posted: Sun May 25, 2008 1:17 pm
by burger2227
Why ask for advise and TOTALLY ignore it?

Some kind of genius or just plain stubborn?

Posted: Sun May 25, 2008 1:58 pm
by TmEE
because it does not work, i still get the error. I can have all the 3000 lines of the program in 3000 separate files and still get the error.

What are you considering?

Posted: Sun May 25, 2008 3:01 pm
by burger2227
Many QB programs will compile at 64K, but not ones that use so many SHARED variables. Why not try to place the arrays into the SUB call parameters?

QB 7 or PDS have some peculiarities also. Did you read the M$ recommendations?

Your code is 3000 lines? Then you are using a lot of code memory also. You could try CHAIN and make a data file to transfer the COMMON SHARED variables if you want a stand alone EXE. COMMON SHARED does not work in Stand alone linked EXE programs.

Ted

Posted: Mon May 26, 2008 12:28 pm
by TmEE
I've read all M$ recommendations and such... no workaround. If I'd use CHAIN, then it would things be called many many times a second and it would kill all performance.
Also, there's about 1000 lines of ASM in a form of library used in the program...

Anyway, I AM working on a FreeBASIC version, making a Windows port of this program... and its required too as I want this tracker to be the best music tool for Sega Mega Drive / Genesis and for that I need to incorporate several more thousand lines of code (there's some custom sound chip emulation required) and it would just be tooooo big pain to do in QB on its own...