Re: question
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 16, 2004
- 523 views
Tone Škoda wrote: > > Derek Parnell wrote: > > > > 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. > > What would happen when when I would do 'tmp={}' before I modify 'data'? Would > there > be any copying going on? Because if yes, interpreter at would have to do these > two > things: 1) delete memory of 'tmp' 2) allocate memory for 'data'. And these two > memories > would contain same data. procedure main () sequence tmp sequence data tmp = f () -- tmp refers the sequence data returned by f(), -- and this point that is the only reference to it. data = tmp [2] -- data refers to tmp[2] tmp = {} -- tmp drops reference to f() return sequence, but the -- sequence's contents are not deleted 'cos of the -- refers to the 2nd element. -- There is some 'expansion' space defined at the end of a newly -- created sequence. So this append would most likely not -- cause a copy to happen but the expansion area would shrink. data = append (data, "something") -- So the original sequence returned by f() is still in RAM -- and there probably hasn't been any copying done. ... end procedure If you don't do the "tmp = {}" then the append would have to make a copy of the contents because 'tmp' would still be referring to it. > This is one thing because of which I am thinking of switching to C, because > there you > have pointers and things like this are crystal clear. Yes, but the responsibility is on you and your perfect code to always "get it right". That is why I stay away from C. BTW, this is all speculation as to how Eu works because I haven't actually examined the source code of the Interpreter. -- Derek Parnell Melbourne, Australia