1. Memory use (VB6)

I have written a very simple routine to calculate and list the factors in any number. This has been documented in the past in the Lounge and works fine for all numbers except very high numbers. The programme uses a simple incremental loop that divides the number and checks if is an integer.

I was toying with very large numbers, in the quadrillions when I found that it could run for up to 3 hours, by which time the PC was needed for other things (Don't ask but it involved children)

Is there a process or method that can speed up loop calculations?

This is not a question on how to do factoring, just a general one about looping and processing speed as it will come in handy for another project.

2. Re: Memory use (VB6)

I don't think there is a magic tip for speeding up loops in general. For specific problems involving looping, such as sorting arrays, searching for text in a file, factoring a number, etc., there are very clever algorithms that are enormously faster than any "naive" method, but they are always highly specific to the problem.

3. Re: Memory use (VB6)

Hi Hans

Thanks for this, I am aware that my loop was rather prohibitive, just needed confirmation as I am toying on another idea.

4. Re: Memory use (VB6)

Does your loop involve dyanamic arrays that you keep ReDim-ing? I have read that VB is not very efficient in that area.

5. Re: Memory use (VB6)

There are published factoring algorithms, designed to be efficient for paricular purposes.

What algorithm are you using?

6. Re: Memory use (VB6)

Hi Howard

In my naivity I started using a very simple loop:

...

for i = 1 to x/2 ' x being the number I wish to factor

if thefactor/i=int(thefactor/i) Then

rest of code

next i
...

This obviously is fine for numbers, say, up to 10^9. This is a real number crunching routine that eventually get's the result. Now I am toying with the idea of a factor sieve but on looking at it I would still have to use a loop...or am I thinking the wrong way here?

7. Re: Memory use (VB6)

If you're really interested: Integer factorization <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

8. Re: Memory use (VB6)

Thanks Hans

Funnily enough (or sadly depending on your point of view) I bookmarked this earlier <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>I may have to lie down in a darkened room now

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•