Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Rebol Memory Allocation Strategy?

From: ingo:2b1 at: 21-Sep-2002 22:43

Hi Tim, Am Sam, 2002-09-21 um 19.12 schrieb Tim Johnson: <...>
> Let's say we have a function > > my-f: func[][str: make string! 8192 ; untested code > ; appends much data to str.... > ] > > and that function is called any number of times. > > Now, does that mean that rebol has to allocate 8092 bytes > of memory every time that 'my-f is called? > > ==>>If that is so then would not the following be more > efficient? > > my-obj: make object![ ; untested code > str: make string! 8192 > _my-f: func[][ > clear str > ; appends much data to string... > ] ; end function > ] ;end object > > Would not 'str be allocated just once and that would > be during evaluation of my-obj?
As far as I know you're right. A few additions, though ... my-obj: make object![ ; untested code str: make string! 8192 set 'my-f func[][ clear str ; appends much data to string... ] ; end function ] ;end object this way you can just use 'my-f, without having to think about the object! (no my-object/my-f needed). _or_ you could use my-f: func[/local str][ str: "" clear str ; appends much data to string... ] ; end function 'str being a literal string, it will be retained over function invocation. Of course the first usage of the func might be slow, because 'str would have to slowly grow, while being appended to. _or_ you use the ideas someone else woll surely come up with. Kind regards, Ingo