Re: heavy loop functions slow



On Tue, Apr 8, 2008 at 7:17 AM, Michael Linfield <globyy3000@xxxxxxxxxxx> wrote:
Alright so I was playing with my large amounts of data and ran into yet
another problem with shoving it into a loop that requires a substantial
amount of memory.



dataArray = []
output = arrayOut.to_s.chop!.split(",")

set arrayOut to nil if you don't need it any more.

output1 = output[0..356130]
output2 = output[356131..712260]
output3 = output[712261..1068390]
output4 = output[1068391..1424521]

You dont need output here, set it to nil to allow for garbage collection

count = 0
output1.each do |out|
out = out.to_i
push = hashRange[out]
dataArray << push
count+=1
puts "#{push} - #{count}" #Testing purposes
end

1. you can convert the output to numbers in one pass, though use
benchmark to see the actual gain:

output = arrayOut.to_s.chop!.split(",").map {|out| out.to_i }

2. if you are looking for numbers only, you can do something like

output = []
arrayOut.to_s.chop!.scan(/\d+/) {|out| output << out.to_i }
(you can count the items, and switch to output2 when output1 has
enough, thus 1. creating smaller arrays, 2. doing two things in one
step.)

3. even in this case, you still have both the original arrayOut and
the long string (.to_s) in memory.
It might be faster, if you could iterate through the array without
creating the intermediate string. The question is 1. will it help? 2.
Is it worth it?

.



Relevant Pages

  • Re: newbie: deactivate query before freeing?
    ... However, to make sure that the memory gets freed, you would have to ... call Free before you assign nil. ... Use Free to destroy an object. ... if the object reference is not nil. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Strange EAccessViolation which I cannot figure out...
    ... Constructors are documented to always set their objects' fields to zero, nil, empty, or unassigned. ... that you should not assume the class to Nil your fields for you automatically in the constructor. ... When memory is allocated, Delphi likes to zero it out, in this case ...
    (comp.lang.pascal.delphi.misc)
  • Re: [9fans] segfree() - more details?
    ... I think russ has added this functionality to his kernel. ... return nil; ... process memory segments - NSEG always last! ... So you would need separate memory segments in between too. ...
    (comp.os.plan9)
  • [opensuse] jedit failing on openSUSE 11.0
    ... I am unable to run jedit on openSUSE 11.0. ... GC Warning: Out of Memory! ... Returning NIL! ...
    (SuSE)
  • Re: Copy an IStorage interface to an IStream interface for ATTACH_OLE attachments
    ... Now I want to just stream that to memory. ... function CreateMemoryStreamFromIStorage shown in the link below and it appears to copy to memory ... intfStream: IStream; ... OleCheck(Storage.CopyTo(0, nil, nil, NewStorage)); ...
    (microsoft.public.win32.programmer.messaging)