Author Topic: setting up large arrays  (Read 2536 times)

Offline Gary

  • Dr. Type
  • ****
  • Posts: 313
    • View Profile
setting up large arrays
« on: 2016-Jul-07 »
I have a program I am working on that requires a few very large arrays to be set up on start up as look up tables. The amount of data in each of them is anything up to 200,000 entries.

I have the entries in a text document ready to paste into a DIMDATA line but it looks like GLBasic can't handle really really long line in the editor and just locks up when I paste the data in

Is there any other solution to my problem without having to resort to reading in the data from a file at start up and also can GLB handle arrays of that size?

Thanks
Gary

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3678
    • View Profile
    • Space Fractal
Re: setting up large arrays
« Reply #1 on: 2016-Jul-07 »
You can't just read them as data from the txt file directly?
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Gary

  • Dr. Type
  • ****
  • Posts: 313
    • View Profile
Re: setting up large arrays
« Reply #2 on: 2016-Jul-07 »
would rather have them hidden away from prying eyes and being accidentally deleted or edited but will go for the load option if thats the only way

Offline Gary

  • Dr. Type
  • ****
  • Posts: 313
    • View Profile
Re: setting up large arrays
« Reply #3 on: 2016-Jul-07 »
trying to set them up via the data file but seem to be having issues opening the file

my code is

Code: GLBasic [Select]
OPENFILE(1,"47.txt",1)
FOR a = 0 TO 40
READLONG 1,temp%
win47[a] = temp%
NEXT
CLOSEFILE 1

to open and read the file attached which was generated by another GLB program to contain 40 longs but I am getting a error of No File. The file is in the right directory and exists so at a bit of a loss where I'm going wrong


Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3678
    • View Profile
    • Space Fractal
Re: setting up large arrays
« Reply #4 on: 2016-Jul-07 »
You would end up using double memory using large data which is not designed in that way. Large data is also better from data files really. You can also crypt or hash them eventually.

I'm normally use READLINE using a string and then pass to a variable.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: setting up large arrays
« Reply #5 on: 2016-Jul-07 »
Yep. READLINE from a .txt file into an array is how I'd do it too.
I came. I saw. I played.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: setting up large arrays
« Reply #6 on: 2016-Jul-08 »
You could encode them onto a bitmap and then just read it in, then decode the bitmap a rgba pixels as a 32bit number. This would be quite fast a reading it in and double as a simple encryption. Just an idea.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: setting up large arrays
« Reply #7 on: 2016-Jul-08 »
Gary, to check if the file exists in your current directory, use (copied from the GLBasic User Manual):

Code: GLBasic [Select]
ok=DOESFILEEXIST("test.txt")
IF ok
 PRINT "Test.txt exists", 100, 100
ELSE
 PRINT "Test.txt does not exist", 100, 100
ENDIF

You may not be reading from the directory you think you are.
Try specifying an absolute path for testing.
Or use the GETCURRENTDIR$() to see which one you're in.
« Last Edit: 2016-Jul-08 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3678
    • View Profile
    • Space Fractal
Re: setting up large arrays
« Reply #8 on: 2016-Jul-08 »
I'm did the bitmap thing for a H.E.R.O in the past :-).

The main issue can been lost of depth with 16bit graphics, which can cause imprecise, which I'm also seen that in that game. So it's does have issues on its own.

But using data with large data is nowhere good idea.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: setting up large arrays
« Reply #9 on: 2016-Jul-11 »
Write the data to a cache file in binary format, maybe?

Gesendet von meinem GT-N7100 mit Tapatalk