r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

[unknown: 5]
29-Apr-2008
[10379]
Thanks guys, I think I got a solution.
BrianH
29-Apr-2008
[10380]
Cool.
btiffin
29-Apr-2008
[10381]
Cool;  A little background for Brian's sake.  I bumped into this 
trying to move my LOCATE routine to TRETBASE so I was using system/words 
as a source for testing.  Didn't make it past entry 122  <   to lit-word! 
 didn't make it past 111  '/   kakks too.
BrianH
29-Apr-2008
[10382]
If you think that's bad, look at this:
>> [<]>]
== [<]>]
[unknown: 5]
29-Apr-2008
[10383]
hehe I'm dizzy
BrianH
29-Apr-2008
[10384]
>> length? [<][>]
== 1
btiffin
29-Apr-2008
[10385]
Nice tags.   :)   Leave it to Mr Hawley to get the crux
[unknown: 5]
29-Apr-2008
[10386]
Sees it as a tag
BrianH
29-Apr-2008
[10387]
Nasty, eh? :)
[unknown: 5]
29-Apr-2008
[10388x2]
yes ;-)
I think I'm on to something in REBOL and I want some input on this. 
 If I define a block in a function such as:


my-func: func [data /local blk][blk: copy []  append blk data print 
blk clear blk]


Now even though blk is cleared will the memory still be allocated 
to the size the blk expanded to accomodate the data argument?


If so, instead of clearing blk would it be better to unset or set 
blk as none at the completion of the function?  I'm just guess that 
REBOL's garbage collector wouldn't want to clear the memory allocation 
of blk since it doesn't seem efficient to do so.
BrianH
29-Apr-2008
[10390]
That kind of thing was the original motivation for the ALSO function. 
Try this:

my-func: func [data /local blk][blk: copy []  append blk data print 
blk also blk blk: none]
[unknown: 5]
29-Apr-2008
[10391x2]
forgot what the source of also looked like.  I might need to load 
2.7.6
So is the fix really to just set blk to none?
BrianH
29-Apr-2008
[10393x2]
also: func [
    {Returns the first value, but also evaluates the second.}
    value1 [any-type!]
    value2 [any-type!]
][
    get/any 'value1
]
Yes, that is the fix. You should also set data to none.
[unknown: 5]
29-Apr-2008
[10395]
Yeah good point.  So we really don't need ALSO to free the memory 
then right?
BrianH
29-Apr-2008
[10396]
ALSO is to let you return a value assigned to a variable, and still 
be able to unset the variable.
[unknown: 5]
29-Apr-2008
[10397x2]
Thanks Brian.
Why was ALSO created?
BrianH
29-Apr-2008
[10399]
For cleanup.
[unknown: 5]
29-Apr-2008
[10400x2]
I don't fully comprehend the also function.  I know it is getting 
the value but why pass it twice?
so really you would always want the second value to be word: none 
correct?
BrianH
29-Apr-2008
[10402x2]
It's an evaluation trick. It evaluates two expressions and returns 
the value of the first. You can do your cleanup in the second expression. 
If your cleanup is more complex, put it in a paren. The value returned 
by the second expression is taken and ignored.
The second expression clond be a close statement, for instance.
[unknown: 5]
29-Apr-2008
[10404x2]
So the get/any is just to ensure that a pointer has been established 
then right?
That might not sound correct to you but I think I know why you did 
that.
BrianH
29-Apr-2008
[10406]
It is just there to pass along the first value.
[unknown: 5]
29-Apr-2008
[10407x2]
Exactly - ok got ya.
So this would be used as your primary evaluator not as a secondary 
evaluator called just to do cleanup.
BrianH
29-Apr-2008
[10409]
? Sure, if I understand you correctly.
[unknown: 5]
29-Apr-2008
[10410]
It's alright I get it now.   I was thinking this function was more 
complex than it is.
BrianH
29-Apr-2008
[10411]
Here's another example of its use from 2.7.6:
first+: func [
	{Return FIRST of series, and increment the series index.}
	[catch]
	'word [word!] "Word must be a series."
][
	throw-on-error [also pick get word 1 set word next get word]
]
[unknown: 5]
29-Apr-2008
[10412]
yeah I recall seeing that one.
[unknown: 5]
1-May-2008
[10413x2]
Is there anyway in REBOL2.7.x to force an immediate garbage collection? 
 Just invoking recycle doesn't seem to do it.
The invoking of it does work sometimes so I assume there is some 
type of timing algorithm at play.
Gregg
2-May-2008
[10415x2]
What, specifically, do you want to GC that isn't being GC'd when 
you think it should?
Or, rather, why do you need to GC something immediately?
btiffin
2-May-2008
[10417]
Paul;  It's all pretty much voodoo to me, but the few times I care, 
I start with http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=free-mem.r
[unknown: 5]
2-May-2008
[10418x2]
Gregg, I was just under the impression we had that kind of control. 
 I'm hoping your question is confirmation that we don't so at least 
I'm not missing something.
Yeah brian. I have seen that free-mem function in the past and obviously, 
it is just setting a word to none and calling recycle.  But when 
the recycle is invoked we don't "see" the clean-up immediately.  
In other words the GC doesn't immediately respond.  This might be 
a good design but I would have hoped that when we wanted to we could 
immediately "see" the results of the free memory instead waiting 
for GC to run the task when it decides to.
Gregg
2-May-2008
[10420x2]
AFAIK we don't have that kind of control Paul. The best you can do 
is make sure the things you want to release are set to NONE and do 
a RECYCLE.
Make sure things aren't referenced that is.
Henrik
2-May-2008
[10422]
use fewer locals and reuse global series if possible
[unknown: 5]
2-May-2008
[10423]
Thanks Gregg and Henrik.  At least I know I should expect to "see" 
an immediate release of the memory by the REBOL process.  I just 
wanted to make sure I wasn't missing some REBOL magic somewhere.
Gabriele
2-May-2008
[10424]
the GC makes the memory available again to rebol, not necessarily 
the OS.
[unknown: 5]
2-May-2008
[10425]
Ahhh, thanks Gabriele.  What about the OS? - can we return that freed 
memory to the OS instead?
Henrik
3-May-2008
[10426x2]
should any object not drop its bindings using this:

load mold/all object

?
ah, load mold object solved it.
Gabriele
3-May-2008
[10428]
i don't think there is any way to force rebol to return the memory 
to the OS, and I don't think there's any need either, but that depends 
on the OS i guess.