IDidNotDoIt
New Member
Hi, all!
I'm trying to play with prime numbers and implementing several methods for calculating them.
When arrived to Eratosthenes' sieve I need to use as much as memory as possible, so my algorithm starts dimensioning an array and sizing downwards until no Error 7 Out of Memory happen.
Then I initialize the redimensioned array and Excel always crashes when referencing the nth-1 array element. I tried different values for the upper bound limit (90%, 80%, 75% of max value, max value minus 2, minus 10...) and it keeps on crashing at the before last element reference.
Can anybody help me with this issue?
Tanks for your time and best regards.
I'm trying to play with prime numbers and implementing several methods for calculating them.
When arrived to Eratosthenes' sieve I need to use as much as memory as possible, so my algorithm starts dimensioning an array and sizing downwards until no Error 7 Out of Memory happen.
Then I initialize the redimensioned array and Excel always crashes when referencing the nth-1 array element. I tried different values for the upper bound limit (90%, 80%, 75% of max value, max value minus 2, minus 10...) and it keeps on crashing at the before last element reference.
Can anybody help me with this issue?
Tanks for your time and best regards.
Code:
Option Explicit
' public constants
Public Const gkiDefault = 255
Public Const gkiNumByt = 20
Public Const gkiCycle = 4
Public Const gksCycle = " 2 2 4 2"
Public Const gklLen = 50000
Public Const gknFactor = 1 '0.9 0.8 0.75
Public Const gkiKb = 1024
' public declarations
Public gArr() As String * gklLen
Sub TestSize()
'
' constants
'
' declarations
Dim sCycle() As String, iCycle() As Integer
Dim sDefault As String, sElement As String
Dim lSize As Long, lSizeX As Long
Dim I As Long, A As String
'
' start
' array size
lSize = gklLen
On Error Resume Next
Do
Err.Clear
lSize = lSize - 1
ReDim gArr(1 To lSize)
Loop Until Err.Number = 0
Debug.Print "lSize act: "; lSize
On Error GoTo 0
' initialize
' cycle
sCycle = Split(gksCycle)
ReDim iCycle(1 To UBound(sCycle))
For I = 1 To UBound(sCycle)
iCycle(I) = CInt(sCycle(I))
Next I
' array
sDefault = Chr(gkiDefault)
sElement = String(gklLen, sDefault)
lSizeX = lSize - 2
For I = 1 To lSizeX
gArr(I) = sElement
DoEvents
Debug.Print I;
Next I
For I = lSizeX + 1 To lSize
' Excel crashes here, in the nth-1 array element referencing.
' No matter which value has lSize, even tried with -2 and -10,
' and it always crashes when referencing before-last array element.
gArr(I) = ""
Next I
'
' process
'
' end
'
End Sub