running out of memory

new topic     » goto parent     » topic index » view thread      » older message » newer message

--here's a 'running out of memory' problem I'm having.
--"cut and paste" and see what you get...
--
-- J-TEST-1.EX
-- it's a routine to (create and) add a large sequence of numbers together
--

sequence a, b, c
integer lena, lenb
atom t1

a = repeat(9, 7000000)      --trying it from 1,000,000 to 8,000,000 (+)
b = a

t1 = time()             --begin timing cycle

lena = length(a)        --where a and b are made the same length
lenb = length(b)        --by prepending zeros as necessary
if lena > lenb then
        b = repeat(0, lena-lenb) & b
    elsif lenb > lena then
        a = repeat(0, lenb-lena) & a
end if

c = a                   --ready the result sequence

c = a + b               --add the numbers

c = 0 & a                       --begin the normalizing of the number
for i = lena+1 to 2 by -1 do      --an 'add the carries' routine
    while c[i] > 10 do
        c[i-1] += 1
        c[i] -= 10
    end while
end for
if c[1] = 0 then
    c = c[2..lena+1]
end if

t1 = time() - t1        --end timing cycle

--? c                   --print test results
? lena
? t1

--here's what's happening::::::
--for  1 million digits, it takes 0.5 second
--     5 million digits is 2.09 to 2.42 seconds
--     6 million digits is 2.47 to 2.69 seconds
--     7 million digits is 3.9-5.44-9.83+ seconds plus some disk activity
--     8 million digits, it runs out of memory after much disk activity
--
--my machine = win98, AMD K62 333, 96 MB SDRAM, 788 MB free HDD...
--
--the question is, why do I run out of memory...?
--
--if it's 4 bytes/integer, 8 M * 4 = 32 M * 3 (a, b, c) = 96 M
--but with 96 MB RAM plus 192 MB swap file and 788 MB of HDD free, uhh...?
--I am running a fixed frequency monitor, so no options to go to straight
DOS.
--
--and why the variations on the timing...? (nothing running)
--
--in a similar test program it seems to keep going up to 1 minute, then it's
--"out of memory" after a lot of disk activity. same 8 M numbers.
--
--WHY? thanks...!
--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu