Author Topic: DIM a (Max Index)  (Read 15100 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: DIM a (Max Index)
« Reply #45 on: October 18, 2018, 07:52:39 pm »
What I'm really curious about, at this point, is how do we know that there's always going to be less than 256 occurrences of a number?  You're limiting the counter to a single unsigned byte, but it seems like billions of numbers generated would have a chance of at least one of them occurring more than 255 times.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: DIM a (Max Index)
« Reply #46 on: October 18, 2018, 08:21:16 pm »
The best solution:
Code: QB64: [Select]
  1. DIM TimesProcessed AS _UNSIGNED _BYTE
  2.  
  3. limit = 1000000
  4. m = _MEMNEW(9000000000)
  5. _MEMFILL m, m.OFFSET, 9000000000, 0 AS _UNSIGNED _BYTE
  6.  
  7. starttime## = TIMER
  8. FOR i = 1 TO limit
  9.     FOR j = 1 TO 31 'for 31 q's
  10.         q = INT(RND * 9000000000)
  11.         _MEMGET m, m.OFFSET + q, TimesProcessed
  12.         TimesProcessed = TimesProcessed + 1
  13.         _MEMPUT m, m.OFFSET + q, TimesProcessed
  14.     NEXT
  15. finishtime## = TIMER - starttime##
  16. PRINT USING "#####.### seconds for ###,###,###,### numbers"; finishtime##, 31 * limit

A few cavets here:

1) You need a 64-bit version of QB64 to use this.
2) You need 9GB of ram or so.

On my machine, we process 31,000,000 values in 5 seconds, so I'd guess a billion numbers would take less than 5 minutes. (Compared with 40 seconds for 3,100 values using file storage.)

« Last Edit: October 18, 2018, 08:41:55 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: DIM a (Max Index)
« Reply #47 on: October 19, 2018, 07:41:12 pm »
@Steve
you've used the direct access to the memory! I think that I cannot get so fast results.
I'm no expert to use RAM in this low level mode!
Great lesson.
Programming isn't difficult, only it's  consuming time and coffee

Offline soniaa

  • Newbie
  • Posts: 18
    • View Profile
Re: DIM a (Max Index)
« Reply #48 on: October 22, 2018, 03:32:03 pm »
I have Upgraded the RAM in my Pc;
(old; at the start of this post: 6 GB)
(old; at the middle of this post: 8 GB)
NOW: 12 GB

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: DIM a (Max Index)
« Reply #49 on: October 22, 2018, 03:47:20 pm »
I have Upgraded the RAM in my Pc;
(old; at the start of this post: 6 GB)
(old; at the middle of this post: 8 GB)
NOW: 12 GB

Try a method like the one in reply #46.  Use _MEMNEW and _MEMPUT/_MEMGET to write the values directly to memory.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline soniaa

  • Newbie
  • Posts: 18
    • View Profile
Re: DIM a (Max Index)
« Reply #50 on: October 22, 2018, 03:51:42 pm »
Thank you so much,,,  to all of you !!!

What seemed to me a good way (open c.dat for binary);
I found out to be not good,
when the records stored in this file they become 1 billion, GET e PUT it slows down a lot,
...probably because this method does not use much RAM.
« Last Edit: October 22, 2018, 05:28:30 pm by soniaa »

Offline soniaa

  • Newbie
  • Posts: 18
    • View Profile
Re: DIM a (Max Index)
« Reply #51 on: October 22, 2018, 05:14:51 pm »

- - - - My Problem Is Solved. - - - - -


I've just finished a test;

I inserted in my program the method:      REDIM rec(9000000000) as _UNSIGNED _BYTE
The results  they were excellent !!!  .....much more expected !!!
The speed reached is enormous, my program has runned in phases where I had never-never-never been able to arrive.
The estimated time for to get to the end   it was  2 to 6  years first,

--- NOW The estimated time for to get to the end  it is  1 or 2 hours !!! ---
« Last Edit: October 22, 2018, 05:21:31 pm by soniaa »