Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    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. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.
    Jerry

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    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. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Memory use (VB6)

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

    What algorithm are you using?

  6. #6
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    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?
    Jerry

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    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. #8
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    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
    Jerry

Posting Permissions

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