Re: memory
- Posted by martin.stachon at worldonline.cz Jul 14, 2001
- 405 views
Kat writes: > > Kat writes : > > > Hey all,, > > > > > > I have a short program that opens a 6.8megabyte file, containing text > > > separated by lots of {0}. The object is to eliminate the {zero}s, and > > reformat > > > the results to a more text-looking file. What i can't figure is that > > Taskinfo > > > says Eu is using 86Megabytes in memory to do it! > > > > > > Are these the lines doing it? Is a new instance of data created every time > > it > > > is mentioned in the line?: > > > > > > puts(1,"removing 10 nulls\n") > > > place = match({0,0,0,0,0,0,0,0,0,0},data) > > > while place do > > > data = data[1..place] & data[place+10..length(data)] > > > place = match({0,0,0,0,0,0,0,0,0,0},data) > > > end while > > > > > > > > > Kat > > > > > > > Hello Kat, > > > > Wouldn't be a better way to do the job this code?: > > > > include file.e > > include get.e > > integer fn > > fn = open("file.txt","rb") > > integer char > > sequence result > > result = {} > > while 1 do > > char = getc(fn) > > if char = -1 then exit -- EOF > > eslif char = 0 then -- ignore > > else result &= char -- append to the result > > end if > > end while > > close(fn) > > That way makes 6.8 million file accesses. Eventually, i went to pruning a > little off the front of data in a loop, and processing 50 bytes at a time. The > program eventually was using 120megs of ram and was thrashing the > harddrive for 6 hours, so i killed it off. > > I'd still like to know why it wanted so much memory for a little 6.8meg text > file. > > Kat No, Euphoria doesn't read by 1 byte with getc(). It uses buffer. (See docs) Martin