Re: Slow memory allocation

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

Matt Lewis wrote:
> 
> Haflidi Asgrimsson wrote:
> > 
> > Us getting different results led to me trying you code, ran in less than
> > a second. The culprit line is:
> > 	line = Kparse(o_line, TAB)
> > Although it only slows the code with append(), &= or assignment following.
> > 
> 
> That would have been my next question.  What does Kparse() do?  Could you
> tell us what the results are when you:
> 
>   1) Comment out the Kparse() call
>   2) Comment out the assignment to table
>   3) Comment out the Kparse() call and the assignment (just read and ignore)
> 
> Matt Lewis
> 
Kparse is from kparse.e
--KPARSE.E (parse with keep)
--(c) 05/01/104 Michael J Raley (thinkways at yahoo.com)
--Turns a string of delimited text into a list of items,
--while retaining the position of empty elements. 
The function is below
So string like "1\t2\t\t3" is converted into list: {"1","2","","3"}

In all three cases I get nearly instant response, only when both lines:
	line = Kparse(o_line, TAB)
	table = append(table, line)
then the CPU runs for 25 seconds.
This must be some kind of late typechecking because if TAB is replaced by 
a sequence. Then this takes only about 2 seconds.
	line = Kparse(o_line, "9")



--------------------------------------------------------
global function Kparse(object s, object o) 
 sequence clipbook, parsed_list
 atom ls, lc, clip

 if atom(s) then return s end if 

 clipbook = {}
  parsed_list = {} 
  ls = length(s)

--convert atom delimiter into a 1n sequence 
 if atom(o) then o = {o} end if 

--bookmark the position of all delimiters in 1 pass
  for a = 1 to ls do  
    if match({s[a]},o) then clipbook &= a
    end if  
   
  end for

  lc   = length(clipbook)
  if lc = 0 then return {} end if 

-- find the text between the recorded delimeter positions to create a list.
-- First check to see if the first bookmarked delimiter starts sequence s

  clip = clipbook[1]
   if clip = 1 then              -- Yes. Create the first element empty
    parsed_list = {{}}         
   else 
parsed_list = {s[1..clip-1]} -- No. Build the first element from s up to our
    bookmark
   end if 

-- now we can process the rest of the sequence 
  for ic = 2 to lc do
     if clip+1 = clipbook[ic] then
       parsed_list = append(parsed_list,{})
     else 
       parsed_list = append(parsed_list,s[clip+1..clipbook[ic]-1])
     end if 
     clip = clipbook[ic]
   end for 
--test if end of s is past last delimeter   
   if ls > clipbook[lc] then 
     parsed_list = append(parsed_list,s[clipbook[lc]+1..ls])     
   end if 
  
   return parsed_list
end function


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

Search



Quick Links

User menu

Not signed in.

Misc Menu