Re: Garbage and macros
Daniel Johnson writes:
> I heard mention of garbage collection recently. Does Euphoria
> have a fully automatic garbage collection system like Java ?
Yes, although Euphoria and Java implement garbage collection
quite differently, and Euphoria's data structures are fundamentally
more flexible than Java's, which are more similar to those in C++.
In Java you must allocate space using the "new" operator.
In Euphoria it's completely automatic.
> If I read a whole file into a sequence, should I null the sequence
> after I have finished ?
If you need to save space, it may help to set a large sequence
to {} when you no longer need it's value, but remember that
Euphoria will automatically free all the private variables of a routine
when that routine returns. Whenever you assign a new value to
a variable, any space used by the previous value is recycled.
> In some assemblers you have the option of macros.
> These are like subroutines except that they are
> inserted into the code at compile-time ie they run
> inline. This of course saves the time of a subroutine call,
> and also saves repeating code. This could be
> extremely handy in Euphoria, for example if you
> use the same short piece of code several times
> in a prog, and call it a large number of times eg
Rather than adding a new language keyword or feature,
I'd prefer to build a smarter optimizer, that will automatically
in-line small routines when converting source code to
intermediate code.
> The other *real* advantage of macros is that they could allow
> conditional compilation.
> if condition then
> macro stuff(integer a)
> return power(a+1,2)-3
> end macro
> else
> macro stuff(integer a)
> return a --This compiles to nothing
> end macro
> end if
Again, I'd rather have the optimizer avoid generating
intermediate code, when it's obvious at compile-time that
an if-else condition is going to always be true or always be false.
> Then when you run your for-loop, you have saved 1000000 wasted
> function calls.
The overhead of making a call depends on how many arguments
you are passing etc. The overhead of a 0-argument procedure call
is less than the cost of two integer multiplies (on my machine).
A 1-argument call is cheaper than 3 multiplies. If you are doing
very little inside a routine, and you are calling it a lot, you'll see a
significant speedup by in-lining the code. This is just as true
in C or any other language. I don't believe that procedure/function
calls are particularly expensive in Euphoria.
Regards,
Rob Craig
Rapid Deployment Software
|
Not Categorized, Please Help
|
|