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

World: r3wp

[Core] Discuss core issues

Pekr
17-Jul-2007
[8494x3]
I want my screen to be removed from memory, and am thinking of putting 
the view code inside func as suggested, defining referenced widgets 
as locals ...
however, I am still not sure memory will be freed after function 
call is finished ...
I will continue in View group ....
BrianH
17-Jul-2007
[8497x2]
I think that the memory is not freed in R2, but is in R3.
Use this function for memory cleanup:

after: func [a b] [:a]
Sunanda
17-Jul-2007
[8499]
According to Gabriele, REBOL never frees memory -- ie never hands 
it back to the operating system.

That means (I think) freed / garbage collected memory is kept in 
REBOL's grasp for reallocation, so subsequent allocations are faster 
than ones that need to go to the opsys. But the memory footprint 
of an application can be higher than you'd expect -- especially (say) 
if you do a lot of memory intesmive work at start up: that memory 
will stay allocated to REBOL throughout the life of the application.

One way to avoid that may be to use CALL to run parts of the application 
under another process. Or perhaps use a webserver and split the app 
into several non FastCGI scripts.
***

I've no idea if R3 does allow for opsys memory handback. It would 
be a useful option to have:
    recycle/for-real
Dockimbel
17-Jul-2007
[8500]
From a fresh REBOL/View 1.3.2.3.1 :

>> system/stats
== 4236013
>> system/stats/recycle
== [1 2054 2054 183 183 1869648]
>> make string! 1'860'000
== ""
>> system/stats
== 6099084
>> system/stats/recycle
== [1 2054 2054 183 183 7088]
>> make string! 10'000
== ""
>> system/stats
== 3210049
>> system/stats/recycle
== [2 6385 4331 543 360 2999280]

Just guessing: 


REBOL triggers a GC when the "ballast" value (the last one in the 
block) reaches 0. Then the GC frees only the values that aren't referenced 
anymore. So GC are predictable if you know exactly how much memory 
is consumed by each evaluated expression. Remember that it very easy 
in REBOL to keep hidden references on values (like functions persistent 
context)...


So that way, it keeps a fast average time for new allocations. (I 
guess also that series! and scalar values are managed with different 
rules).


The above example also shows that REBOL gives memory back to the 
OS, but the conditions for that to happen are not very clear to me. 
The GC probably uses complex strategies. If the GC internal rules 
were exposed, we could optimize the memory usage of your applications, 
and probably the speed too.
Pekr
17-Jul-2007
[8501x2]
Does R3 have R2 GC, or new implementation?
BrianH: could you please explain, how your 'after function frees 
memory? :-)
BrianH
17-Jul-2007
[8503]
after: func [a b] [:a]

something: func [/local a] [a: make string! 10'000'000  after a a: 
none]


If you use after a lot, the next call will displace the memory taken 
by the last. If you don't want to wait, call
    after none none
Geomol
17-Jul-2007
[8504x2]
Que? What's the point here?
Is it a way of cleaning up, so the local a doesn't point to some 
mem area, and so the garbage collector can do its job?
BrianH
17-Jul-2007
[8506x2]
Otherwise (in R2) the function SOMETHING will retain the value of 
the word a until the SOMETHING function is called again, or is itself 
collected. If that value is large it could be a problem - hence the 
really large value in my example.
In R3 those words are cleared on function return, so that particular 
problem doesn't arise. There are other kinds of cleanup that AFTER 
can help with though.
Geomol
17-Jul-2007
[8508x4]
I situations with strings (or series in general) like that, I use 
to put the function and the variable in a context and do
clear a

when it's needed. That way I reuse the mem area. Would I need the 
after function? hmm ...
I have never used such technique, but I'll consider it.
To make it clear, I would do something like:

context [
a: ""

something: does [clear a  ... ]     ; do something with a, maybe 
filling it with lots of data or whatever
]
There should of cource be some more code before the end bracket ending 
the context. It was just to illustrate.
Gabriele
17-Jul-2007
[8512]
doc, stats decreases, however size in task manager seems to stay 
the same, so i don't know if memory is actually deallocated or kept. 
maybe the os keeps it for the process.
Dockimbel
17-Jul-2007
[8513x2]
if you play a little more with this example allocating big buffers 
then releasing them, you'll see memory used going up and down (I 
even could go back close to initial state after something like  a: 
make string! 100'000 recycle). So REBOL releases some parts to OS, 
but it's hard to predict how much and when...
(watching in task manager)
Geomol
19-Jul-2007
[8515]
What is PATH used for?
>> ? path
USAGE:
    PATH value selector 

DESCRIPTION:
     Path selection.
     PATH is an action value.

ARGUMENTS:
     value -- (Type: any)
     selector -- (Type: any)
Rebolek
19-Jul-2007
[8516]
From RT Q&A:

Q: While reviewing the action! functions, I noticed the path action. 
The doc comment says "Path selection.". The parameters aren't typed. 
Does anyone know what this action does, and how to use it? Or whether 
it can be or should be called directly at all?


A: the PATH action is what the interpreter uses to evaluate VALUE/selector 
expressions for each datatype. It is an internal action and has no 
external purpose in programs. These kinds of words often appear as 
a sort of "side-effect" from how REBOL is structured.  Datatypes 
are implemented as a sort of object class, where the interpreter 
"sends messages" to the class to evaluate expressions. The PATH action 
is a message that tells the datatype to perform a pick-like or poke-like 
internal function.

Some other discussion:

http://www.rebol.org/cgi-bin/cgiwrap/rebol/aga-display-posts.r?post=r3wp152x1804

http://www.rebol.org/cgi-bin/cgiwrap/rebol/aga-display-posts.r?post=r3wp157x7205
Geomol
19-Jul-2007
[8517]
Thanks!
Louis
22-Jul-2007
[8518x2]
s: "Hi engkau. Mengapa kaulari? Topikau ada di sini dan jaskau ada 
di sana."


In string s above, is there an easy way to replace (with "engkau" 
all instances of "kau" that are not preceeded by  " " (a space) or 
immediately followed by a letter?
In other words, I only want "kau" to be replace with "engkau" when 
"kau" is preceeded by a letter and followed by a space or puncuation 
mark.
Geomol
22-Jul-2007
[8520x3]
Do you want "engkau" to become "engengkau"?
One solution:


s: "Hi engkau. Mengapa kaulari? Topikau ada di sini dan jaskau ada 
di sana."
p: s

while [not none? p: find p "kau"] [either all [p/-1 <> " " find " 
,." p/4] [insert p "eng" p: skip p 6] [p: skip p 3]]
If you don't want "engkau" to become "engengkau", you can use:


while [not none? p: find p "kau"] [either all ["engkau" <> copy/part 
skip p -3 6 p/-1 <> " " find " ,." p/4] [insert p "eng" p: skip p 
6] [p: skip p 3]]
Louis
22-Jul-2007
[8523x3]
Geomol, thanks!  I'll do some testing and get back with you in a 
few hours.
I have to get some sleep first. :>)
Geomol, perfect! and simple. Many, many thanks! You have saved me 
a lot of time.
Geomol
23-Jul-2007
[8526]
:-) I'm glad to help!
btiffin
26-Jul-2007
[8527]
Is there a way to detect if a script is run from >> do %script.r 
 versus  $ rebol script.r  ??
I'd like to  either from-console [halt] [quit]
Geomol
26-Jul-2007
[8528]
Can't you check on some of the values in system/script ? Maybe system/script/header 
or system/script/args ?
btiffin
26-Jul-2007
[8529x2]
I was playing with those...but you tweaked a memory.  There was a 
weirdness in the DevCon presentation...it was system/options/script. 
 Thanks John.
Much nicer error abends now.
Anton
26-Jul-2007
[8531]
Perhaps system/console/history.
Volker
26-Jul-2007
[8532x2]
parent of system/script. each 'do adds a header there while the sub-script. 
none? system/script/parrent/parrent IIRC.
..while the sub-script  runs..
try probing system/script from the subscript to figure it out.
btiffin
26-Jul-2007
[8534]
I think it comes down to  system/options/script  This seems to only 
be set (at least in GNU/Linux land) when the shell $ rebol script.r 
is used to kick start.  I'm pretty sure I can use this for a reasonable 
bail test.   Regardless of how many do levels down,  system/options/script 
 is the original shell start script name (or none if do'ed)  This 
is reasonable right?  If the user starts from the shell, bail to 
the shell, starts from the console, bail to the console.
Volker
26-Jul-2007
[8535]
i thought you want to check if the do is from another script. you 
want from the console. then you are right.
btiffin
26-Jul-2007
[8536]
Thanks Volker, your advice will likely come in handy in the not too 
distant future.  :)
Geomol
27-Jul-2007
[8537x3]
Given a block with one element:
>> blk: [1]
== [1]
I move the blk pointer forward one position:
>> blk: next blk
== []
I then append one element:
>> append blk 1
== [1 1]

and the head of blk is shown, which is the behaviour of append. The 
address of blk is the same:
>> blk
== [1]
I now clear the whole block:
>> clear head blk
== []
and append yet another element to the now empty block:
>> append blk 1
== [1]
But blk now points to the tail of the block!
>> blk
== []

Shouldn't I see the element at the position of blk? I mean, blk should 
now point to the head of the block, right? I couldn't find this in 
RAMBO.
Funny thing is, that if I append yet another element:
>> append blk 2
== [1 2]
the blk pointer now point at element 2:
>> blk
== [2]

So blk had the position 2 all the time, even when the block was empty!?
How does R3 behave in this regard?
Rebolek
27-Jul-2007
[8540]
tried all steps in r3 and looks exactly same
Gregg
27-Jul-2007
[8541x2]
clear head blk
 doesn't reset 'blk to the head of the series. If you do:

blk: head blk
clear blk

you should get what you expect.
or "blk: clear head blk"
btiffin
27-Jul-2007
[8543]
Documentation question again.  Are rebols better described as "programmers" 
or "script writers"?  Target audience; new users (of the rebol.org 
script repository in particular)  And I'll take other suggestions.