Re: question

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

Tone Škoda wrote:
> 
> 
> I have a question for how interpreter does its internal things.
> 
> Example:
> 
> }}}
<eucode>
> function f ()
> 	return {1, "large data"}
> end function
> 
> procedure main ()
> 	sequence tmp
> 	sequence data
> 	tmp = f ()
> 	data = tmp [2]
> 	data = append (data, "something")
> 	-- If I assume correct previous line had to make
> 	-- a copy fo "large data", which would slow things down,
> 	-- and there are now two copies of "large data",
> 	-- one in 'tmp' and one (modified) in 'data'.
> 	--
> 	-- Would it be better and faster if after line
> 	-- data = tmp [2]
> 	-- I would do this:
> 	-- tmp = {}?
> end procedure
> 
> 
> </eucode>
{{{


Yes, 'data' would have been copied when the append was done because
after the append, 'data' contains different values from 'tmp[2]'. But
til that point, there would have only been one copy of the data in RAM.

If you do 'tmp={}' I think that this will add the RAM that tmp was
using to the pool of RAM that Euphoria can reuse for this application.

If you are running this as a Windows app, I also think that the released
RAM may also be available for other apps too.


If you can arrange it, I suspect that you can preallocate space in some
situations...

function f ()
	return {1, "large data" & 0}
end function

procedure main ()
	sequence tmp
	sequence data
	tmp = f ()
	data = tmp [2]
     data[length(data)] = "something"
  . . .
end procedure


But it would probably be a good idea to deallocate the 'tmp' 
too. I don't know when Euphoria's garbage collector runs. It might
not sweep this until considerable some time after 'tmp' was deallocated.

-- 
Derek Parnell
Melbourne, Australia

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

Search



Quick Links

User menu

Not signed in.

Misc Menu