Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

large array size

Status
Not open for further replies.

edouardo

Programmer
Oct 6, 2002
3
NO
Hi everyone
I'd like to do some image processing of a 301K
image (an array of 640 * 480 pixels with 256
graylevels) How can I do it? Right now I have:

SCREEN 13
DIM a%(23000)
a$ = "image.bmp"
OPEN a$ FOR BINARY AS #1
FOR j% = 1 TO 21000 STEP 2
GET #1, j%, a%(j%)
NEXT
CLOSE

It seems I am limited to about 20000-30000
probably because DIM is not large enough
How can I read the whole image?
 
U need to dynamically dim the array.
On command-line, there is a switch for it.
For after compile, put a '$DYNAMIC before the DIM. Cheers
Erez Sh.
 
QB array sizes aren't limited to 64K, if you dynamically allocate it, but the range of indices is still limited to 32768. To overcome this, allocate a DOUBLE array. One DOUBLE is 8 bytes long, so
'You may need to load QB using QB/AH
'$DYNAMIC
DIM a#(0 TO 32767)
will give you a 256KB array. You would manipulate it by POKEing into the array (pretend it's a byte array). Unfortunately, 640x480x1byte/pixel=300KB for a 640x480 screen. So even a DOUBLE array isn't large enough. There are three ways around this.
1) You can load directly to the screen, in scanline increments (or larger).
2) You can load into two (or more) arrays, and make two FOR loops that load the first
half and the second half of the bitmap.
3) You can have DOS allocate a huge chunk of memory using interrupts, after you release some using SETMEM.

Since you are doing image processing, I think 2) is the best way. By the way, you can load more than 8 bytes at a time using GET. You can do something like DIM a as string*1024: GET #1,, a. Then you can DEF SEG=VARSEG(a):eek:fs=0: POKE (SADD(a)+ofs),newval. If you use BLOAD, you can load close to 64K at a time. Using INTERRUPT, you can load at least 64K at a time.


 
It is a waste to use an integer or a double to contain single bytes.
use :
DIM a(size) AS STRING * 1
But why load an entire file to memory???

Cheers
Erez Sh.
 
Erez,
I'm not sure if you understood what I meant. I allocated a DOUBLE array for the sole purpose of allocating more than 64K at a time. I still treat it as if it were a BYTE array when I POKE into it. But you reminded me of a point I missed. When you poke into the array, you need to change segments (using DEF SEG), if the array is greater than 64KB.

 
I'm talking about using the GET statement.
I don't think it will load 4 btes to each array element.
I will probably load 1 byte to each.

besides, DIM a(100000) as string*1 works for me
Why shouldn't it work 4 u? Cheers
Erez Sh.
 
Hmmm... I assume it won't work for us because Qbasic doesn't allow us to dimension an array with 100000 elements(?). Tell me is I'm getting close....
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
U can dim an array of 100000 elements! Cheers
Erez Sh.
 
Please give me an example with a one-dimensional array. QB45 help tells me that "The maximum range between array subscript values is 32,767."

I'd be interested in a way around this. Thanks.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Ditto!!! Please provide an example if you will.

--MiggyD
 
Basically, it is limited to 32767 elements, per dimension.
When I said qbasic support 100000 elements, i ment like this:
DIM a(25000,4) as string*1
I works for any size, except for when it's out of memory.
But that's something else. Cheers
Erez Sh.
 
Erezsh,
You're right. I think I forgot that because I was purposely working in QB without the /AH parameter for speed. So Eduardo can just do
REM $DYNAMIC
DIM image(0 TO 639,0 TO 479)
and then load the image, and process it.
 
I have seen 11 responses to my msg about arrays
but I have tried different things, nothing works.
QBASIC/AH does not work (A not allowed)
DIM image (0 to 639, 0 to 479) also fails. I can
only go up to DIM image (0 to 639, 0 to 24)
My version is Q1.0 maybe it's not the latest
Would it help to upgrade? Where can I get it?

In fact how about is I just read the memory with
a loop containing some PEEK and DEFSEG
and write the processed pixels somewhere else with POKE
How can I know where my image lies in the memory of my
Dell PC?
How can I know where to write (dangerous, I do
not want to cover anything?)
I used to have an Oric Atmos in 1985 where I know
exactly what's the address of the hires screen
but on today's PC how can I know where exactly the
files occupy the memory?
Please explain well to me any idea or write the code
because I am not very computer litterate

Edouardo
 
Oh. Old version.
Qb 1.0 probably doesn't support it.
U should upgrade to at least QB 4.0 (4.5 recommended).
Go to:

Using peek and poke can be useful sometimes, but in your case it can cause harm. Unless knowing exactly where to write in memory, u can cause some errors by writing on reserved memory peices (either DOS's or for Qbasic's).
If u want to use peek and poke, u must allocate it first using a variable (for big areas use an array) but then we're back to the first issue.
Cheers
Erez Sh.
 
EDOUARDO:

I have this question for you. Why are you using a STEP through in your loop?

> FOR j% = 1 TO 21000 [red]STEP 2[/red]
> GET #1, j%, a%(j%)
> NEXT
> CLOSE

Wouldn't it be easier to actually fill in the array as a sequential/linear string like:
(array) - chr/byte
(1) - 21,
(2) - 22,
(3) - 23,
(4) - 24,
(5) - 25, ...etc.

Instead of skipping some indicies:
(1) - 21,
(2) - null,
(3) - 22,
(4) - null,
(5) - 23, ...etc.

I'm hopeful that is a precurser to an answer for you, although, I've made plenty of apps for businesses, I've never realy had to deal with graphics in QB. So forgive my ignorance in this matter.

-MiggyD

"The world is shrinking with every new user online."
 
Miggy
Don't worry about the step 2 I don't remember well why
but I know I could see my small image.


My question remains unanswered. Again when I have
a file called image.bmp on my computer how can I know
where it is in the memory (the hex address of where I
can start a for next loop of peek, no more GET #1,blabla
 
Well, sorry I asked.

If you read Toshi's first response...last paragraph...he mentions several memory statements that you'll have to look up in you help files.

-MiggyD "The world shrinks more and more with every new user online."
 
Well folks, it is pretty simple.
The integer in QB is made of 2 bytes.
The file is read byte-by-byte.
So if u read two bytes, you proceed 2 bytes, and not one.
Cheers
Erez Sh.
 
edouardo,

If you want to do image processing in a QB-like language, I recommend Visual Basic. Not only does it simplify visualization of the effect being calculated (if that is desired), but it allows you to have absolutely massive arrays. For instance, the following code would let you process a 1024x768 image:
[tt]
Dim image(0 To 1023, 0 To 767) As Byte
fileNumber% = FreeFile
Open "image.dat" For Binary As fileNumber%
Get fileNumber%, , image()
Close #fileNumber%
'now image() can be processed directly
[/tt]
You'll note also my use of the 'Byte' data type, also available in VB but not in QB. While Visual Basic is not quite as fast as QB, for image processing, which is typically not a realtime type of application, it is clearly superior.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top