World: r3wp
[Core] Discuss core issues
older newer | first last |
Izkata 31-Mar-2009 [13392x4] | Tom: it's not the replace that's doing it... >> "^IKSE" == "^-KSE" >> "^MERV" == "^MERV" >> "^JKSE" == "^/KSE" >> "^IKSE" == "^-KSE" |
but I have no actual answer | |
Well, ^I is a control-i.. and in vim, that inserts a tab. ^- is the tab character in Rebol | |
I must go to class now | |
TomBon 31-Mar-2009 [13396] | thx for the info izkata. |
Geomol 31-Mar-2009 [13397x2] | Paul, I would probably do: o: context [q: "blahblah" f: does [insert q "more blah" q]] And my that have full control over q. It depends on the application, I guess. |
my -> by | |
[unknown: 5] 31-Mar-2009 [13399] | I'll stick with ALSO. ;-) |
Geomol 31-Mar-2009 [13400x5] | Izkata, about the timeout. It seems here, that when the open/binary returns, the data is immediately available, so the timeout has no effect. I'm on OS X, maybe it's different under windows? |
Anyway, I can now see, how you use ALSO with ports. By using a function approach, you choose to copy the data out to some further external computation. And it's up to the user of the function to free the data, when finished. I would take an object approach and store the data in the object. Then external computation can work on the data in the object. I feel, it's confusing using ALSO, but maybe it's just me. | |
An object approach could look like this: Ports: context [ Port: none Data: none Pread: func [URL] [ either error? try [Port: open/binary URL] [ print ["Can't open:" URL] false ][ Data: copy Port close Port true ] ] ] | |
Using it would then be: if Ports/Pread http://www.rebol.com[ ... do something with Ports/Data ... ] | |
Where I see a potential problem with ALSO, is if you in a function load a local var with a huge amount of data, say 1GB. And then to release that data ends your function with: also copy local-data local-data: none At that moment between the two arguments to ALSO, you have 2 GB of data allocated. The first 1 GB is freed, when the garbage collector comes to it. | |
[unknown: 5] 31-Mar-2009 [13405] | So is this your assurance to us that we will never see ALSO in your code? |
Geomol 31-Mar-2009 [13406] | No no, I never say never. ehh ;-) |
Izkata 31-Mar-2009 [13407] | Geomol: [Izkata, about the timeout. It seems here, that when the open/binary returns, the data is immediately available, so the timeout has no effect. I'm on OS X, maybe it's different under windows?] I'm on Ubuntu ;) but yeah, now that I think about it, that's true. Originally it was written differently, and the error appeared to be on the copy. I added it when mininova was timing out on certain requests due to high load - it seemed to make a difference then, but I don't know if it was coincidence or not. |
Graham 31-Mar-2009 [13408] | mininova ? torrenting? |
Izkata 31-Mar-2009 [13409x2] | Yeah, the internal function that RSS plugins on Azureus use broke at some point, so I'm doing it this way now. Much nicer, as I can collect more information, etc |
If you're thinking I'm making a torrrent client in Rebol, not yet ;) | |
Graham 31-Mar-2009 [13411] | I suspect R2 is not up to it ... |
Izkata 31-Mar-2009 [13412x2] | Probably not, but it would be interesting to try |
Then again, R2 has surprised me with my current project | |
Graham 31-Mar-2009 [13414] | networking is not a strong point |
Anton 31-Mar-2009 [13415x2] | Geomol, your last "potential problem with ALSO" is not exclusive to ALSO. It's a potential problem anywhere COPY is abused by a programmer not knowing what's going on. The way to return the large amount of data and to release the local from it is of course like this: also local-data local-data: none |
load-mp3-data: func [file /local contents][ contents: read/binary file ; <- modify contents here also contents contents: none ] data: load-mp3-data %song.mp3 | |
Graham 31-Mar-2009 [13417] | so this frees contents?? |
Steeve 31-Mar-2009 [13418] | just to say there is no need anymore to unset the local vars in R3 |
Anton 31-Mar-2009 [13419x4] | In the load-mp3-data function above, a large binary series is loaded and contents set to refer to it. The ALSO line returns the binary series and unsets CONTENTS so that it no longer refers to the binary series. The usage code below the function definition takes the return value (the binary series) and sets DATA to it. So effectively the variable referencing the binary series has been switched with another one. |
(Steeve, yep.) | |
Graham, no, it just "unhooks" the local word CONTENTS from the binary series data. | |
Which is a good thing to do, because now the function does not maintain a reference to the large binary series after it has been called. | |
Steeve 31-Mar-2009 [13423] | If the contents var is not unset and then the load-mp3 function is not anymre called. Then, the garbage collector can't free the serie because it stays handled by the local var contents. |
Graham 31-Mar-2009 [13424x2] | Hmm. So, one should deference local vars if they pointing to large data sets? |
dereference | |
Steeve 31-Mar-2009 [13426] | yes, In R2 we should |
Anton 31-Mar-2009 [13427] | Steeve, yes, that's right. |
Graham 31-Mar-2009 [13428] | didn't know that ... |
Anton 31-Mar-2009 [13429] | Yes, in R2, functions don't bother to unset their local words on function exit. This was done for speed reasons. Most functions don't need to unset their locals. |
Graham 31-Mar-2009 [13430] | I wonder if that would help with the problem I had before when I was doing OCR on image data .. and kept getting crashes |
Anton 31-Mar-2009 [13431] | Where you running out of memory? |
Graham 31-Mar-2009 [13432] | no |
Anton 31-Mar-2009 [13433] | *Were you.. |
Graham 31-Mar-2009 [13434] | If I turned off recycle, the problem disappeared, but then memory eventually would run out |
Anton 31-Mar-2009 [13435] | That was more likely some external library call problem. |
Graham 31-Mar-2009 [13436x3] | not using external libraries |
I was posting the data to a web server | |
web service | |
Anton 31-Mar-2009 [13439] | That was a memory leak, not really caused by the "local vars not unset on R2 function exit" behaviour. (But perhaps contributed, by misunderstanding, to the leak bug.) |
[unknown: 5] 31-Mar-2009 [13440] | Yes, Graham we need to clear those locals by setting them to none. |
BrianH 31-Mar-2009 [13441] | I use ASLO in R2-Forward for that reason - that was the original reason ALSO was suggested. You don't need ALSO for that in R3 since the locals unset themselves in the new function context model, but it is useful for closing ports and changing directories back. |
older newer | first last |