[REBOL] Re: Rebol Memory Allocation Strategy?
From: carl:cybercraft at: 22-Sep-2002 8:00
On 22-Sep-02, Tim Johnson wrote:
> Hello All:
> I need clarification on rebol memory allocation. I
> programmed in C and Asm for years so am cognizant of
> architectural approaches to memory allocation (well, sort
> of). 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?
> Then 'my-f would only have to reset the "internal data
> pointer" which is trivial in terms of overhead.
> (presuming my-f would be 'happy' with 8192 bytes)
> Comments, nags criticisms appreciated..
Did you mean for the 'str in the function to be global? If so, then
there's no need for the object, as you could just create 'str outside
of the function. ie...
str: make string! 8192
my-f: func[][
clear str
; etc...
]
Not sure what happens when it's local to the function though.
--
Carl Read