Smallest data type for a huge array?

Previous topic - Next topic

doimus

Ok, I'm doing some test on a low res game with huge levels where I need pixel precision data. Actual screen is 256x192 but levels themselves can be huge and i want to have binary (true/false) info on every pixel.

So I tried with GLB arrays and when using int# the biggest (5000x5000) array is taking whopping  200mb ram! Which is a massive overkill for my needs. That array size is an overkill too tbh, but I just amped it up to test mem usage.

Is there a way to DIM the array as boolean only? I tried to inline a _bool type array but my inline jedi skills are pathetic to say the least.


Also, related to this, what is a proper procedure to save huge amounts of data? If I just loop through the array and SAVEBYTE each element, it takes ages to save it. It seems much longer than it usually takes to save a file of that size.

MrTAToad

You have also the usually char, int, float etc datatypes available.  However, I'm not sure whether they can be accessible with all the current commands.

doimus

@MrTAToad - do you mean I can have those data types in basic or inline? I know that variable types do get transfered from inline, but that doesn't work on arrays (GLB arrays are some kind of KittyHello wizardry I do not understand).


@Ocean - that would be exactly what I need, can you elaborate on it a bit more... as I'm not really fluent in anything relating direct operation on bits... :-[

MrTAToad

It would have to be inline unfortunately.  Arrays are one area where it can't be used...

Marmor

My Guess  here u will create a World with pixelcollision !
If so why Not create a Second Landscape Bitmap but only with the collisionsline .
The cool Thing here is u can use ColorS to give the collisionsline a Action .
Red - dead
Green - Bounce
Blue - burn



Or u create a Bank and read the Map in
If u Need only One Bit per Pixel so put  8 Pixel in a Byte , Byte for Byte
Later read this with somthing like peekbit ,Bit (0-7),Bank,Position
Hope this can help


kanonet

#5
An Int is 32bits long, so if you create an int array you can store 32 bits in each entry. Basically its easy to do this and to read/write each single bit. It could be done way more easy with c and pointers, but here is a native GLB approach how to do it:

Code (glbasic) Select
TYPE TBoolArray
a%[]
count%

FUNCTION DIMARRAY%: i%
IF i% = 0
self.count=0
DIM self.a%[0]
ELSE
self.count% = i%-1
DIM self.a%[ASR(self.count%,5)+1]
ENDIF
ENDFUNCTION // DIMARRAY%

FUNCTION REDIMARRAY%: i%
IF i% = 0
self.count=0
REDIM self.a%[0]
ELSE
self.count% = i%-1
REDIM self.a%[ASR(self.count%,5)+1]
ENDIF
ENDFUNCTION // REDIMARRAY%

// sets value in the virtual bool array, use like of bool_array(i) = x
// i = index in 'virtual' array
// x = value you want to set, can be TRUE or FALSE
FUNCTION SET%: i%, x%
LOCAL num% = ASR(i,5)
IF x
self.a%[num] = bOR(self.a%[num], ASL(1,i%-ASL(num%,5)))
ELSE
self.a%[num] = bAND(self.a%[num], bNOT(ASL(1,i%-ASL(num%,5))))
ENDIF
ENDFUNCTION // SET%

FUNCTION GET%: i%
LOCAL num% = ASR(i,5)
i% = ASL(1, i%-ASL(num%,5) )
RETURN bAND(self.a%[num], i) / i
ENDFUNCTION // GET%

ENDTYPE


Bad commented, but im lazy,, hope you still understand how to use it. 8)
Downside is that it has a small overhead and that you cant use FOREACH, use FOR i%=0 to a.count% instead (where a is of type TBoolArray).
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

doimus

Thanks for the explanation, working on it now...  :good:

I've also found this old thread dealing with the same issue:
http://www.glbasic.com/forum/index.php?topic=1471.msg9769#msg9769