Memory problems with user-defined types
Posted: Thu Aug 23, 2007 6:21 pm
I am trying to make a user-defined type to help me define an image. To do this, I of course need an array of pixels, and since the screen in QuickBasic can be a maximum of 640x480 that is how big I want the array to be. So I declare it like this.
TYPE Image
Pixel(0 TO 319, 0 TO 479) AS INTEGER
Palette AS ColourPalette
END TYPE
I get a "Subscript out of range" and I know that this is due to the limit of an array being 64 K. But is there a way I can work around that limit, and still have as big an array as I have above?
If I instead make the array much smaller, it works. But I get the error "Type larger than 65535 bytes" due to the Palette line.
TYPE Image
Pixel(0 TO 159, 0 TO 198) AS INTEGER
Palette AS ColourPalette
END TYPE
My ColourPalette is another user-defined type, consisting of 4 integers. I assume that it is connected to the above error, and can perhaps be resolved in the same way.
If I use REM in front of the Palette statement, I can run my program. But when I try to compile it with BC, I get a "Data-memory overflow" in the following line.
CALL ShowImage(ImageArray(UBOUND(ImageArray, 1)), XCoordinate, YCoordinate)
ImageArray is simply an array of the type Image, that I defined above. It only has one element though, ImageArray(0) so far.
Yes, I'm sure that many of you will look at this and cringe at the thought of all the mistakes I'm sure I have done. That is fine. But please keep in mind that besides making something I find useful, this is to me also a process of learning. So I'll happily take advice and opinions about changes.
TYPE Image
Pixel(0 TO 319, 0 TO 479) AS INTEGER
Palette AS ColourPalette
END TYPE
I get a "Subscript out of range" and I know that this is due to the limit of an array being 64 K. But is there a way I can work around that limit, and still have as big an array as I have above?
If I instead make the array much smaller, it works. But I get the error "Type larger than 65535 bytes" due to the Palette line.
TYPE Image
Pixel(0 TO 159, 0 TO 198) AS INTEGER
Palette AS ColourPalette
END TYPE
My ColourPalette is another user-defined type, consisting of 4 integers. I assume that it is connected to the above error, and can perhaps be resolved in the same way.
If I use REM in front of the Palette statement, I can run my program. But when I try to compile it with BC, I get a "Data-memory overflow" in the following line.
CALL ShowImage(ImageArray(UBOUND(ImageArray, 1)), XCoordinate, YCoordinate)
ImageArray is simply an array of the type Image, that I defined above. It only has one element though, ImageArray(0) so far.
Yes, I'm sure that many of you will look at this and cringe at the thought of all the mistakes I'm sure I have done. That is fine. But please keep in mind that besides making something I find useful, this is to me also a process of learning. So I'll happily take advice and opinions about changes.