English 中文(简体)
When implementing an interpreter, is it a good or bad to piggyback off the host language s garbage collector?
原标题:

Let s say you are implementing an interpreter for a GCed language in a language that is GCed. It seems to me you d get garbage collection for free as long as you are reasonably careful about your design.

Is this generally how it s done? Are there good reasons not to do this?

最佳回答

Language and runtime are two different things. They are not really related IMHO.

Therefore, if your existing runtime offers a GC already, there must be a good reason to extend the runtime with another GC. In the good old days when memory allocations in the OS were slow and expensive, apps brought their own heap managers which where more efficient in dealing with small chunks of data. That was one readon for adding another memory management to an existing runtime (or OS). But if you re talking Java, .NET or so - those should be good and efficient enough for most tasks at hand.

However, you may want to create a proper interface/API for memory and object management tasks (and others), so that your language ("guest") runtime could be implemented on to of another host runtime later on.

问题回答

For an interpreter, there should be no problem with using the host GC, IMHO, particularly at first. As always they goal should be to get something working, then make it work right, then make it fast. This is particularly true for Domain Specific Languages (DSL) where the goal is a small language. For these, implementing a full GC would be overkill.





相关问题
How to write an interpreter?

I have decided to write a small interpreter as my next project, in Ruby. What knowledge/skills will I need to have to be successful? I haven t decided on the language to interpret yet, but I am ...

What programming languages target J2ME?

I recently received a Nokia 5000 phone. Now I want to write software for it. Trouble is, I don t know Java. Now I ve heard of other languages which supposedly make possible development without ...

Python: Analyzing complex statements during execution

I am wondering if there is any way to get some meta information about the interpretation of a python statement during execution. Let s assume this is a complex statement of some single statements ...

Ruby Interpreter crashes with a certain word

Ok, this one s a little ridiculous, and I m almost afraid no one will believe me. But here it goes: I have written a Ruby Rails application that handles content for tons of domains. Now I know this ...

Turing Machine Code Golf

Ok guys, today s goal is to build a Turing machine simulator. For those that don t know what it is, see the Wikipedia article. The state table we are using today is found at the end of the Formal ...

how to implement objects for toy language?

I am trying to make a toy language in c++. I have used boost spirit for the grammar, and hopefully for parser/lexer. The idea is a toy language where everything is an object like javascript and some ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

热门标签