<div dir="ltr"><div><div><div><div><div><div><div><div>The path of least effort, as I previously stated, is to use Boehm-GC.<br><br></div>Reference-counted smart pointers will require that you implement the reference counting in your language, in the generated code. e.g. a statement such as:<br><br></div>p1 = p2<br><br></div>really compiles into:<br><br></div>p1.refcount--; if (!p1.refcount) free(p1)<br></div>p1 = p2<br></div>p1.refcount++<br><br></div><div>If you want your language to be thread-safe, then the increment and decrement operations must be atomic.<br><br></div>Although this is doable, your implementation must be perfect. Any bug, and you will either leak memory, or prematurely free a pointer. I speak from experience. Also be aware that pure reference counting will not collect cyclic data structures.<br><br></div>The "LLVM GC" web page does not document a specific, usable, garbage collector. Rather, it documents the features that LLVM provides to interoperate with garbage collectors that require special considerations for loads and stores. For example, parallel and incremental garbage collection often requires that each pointer dereference first checks if the pointee needs to be scanned. The functionality of the "LLVM GC" support allows this to happen. However, you must still provide your own collector.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 20, 2015 at 9:01 AM, Ahmed Taj elsir <span dir="ltr"><<a href="mailto:meedo456123@gmail.com" target="_blank">meedo456123@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you all,<br>
<br>
David Jones<br>
<br>
>>> You would then implement your own garbage collector in your runtime. If you don't >>> want to do that, then consider using the Boehm-Demers-Weiser conservative<br>
>>> collector. It requires no special support from LLVM.<br>
<br>
I was thinking to implement smart pointer instead of using GC , I mean<br>
like this:<br>
>>> obj b = new obj();<br>
b will automatically be instantiate as smart pointer (which will be<br>
deleted automatic also).<br>
I don't know if it's bad idea or not , but that what I thought .<br>
<br>
Another solution is to implement GC using LLVM GC (described here<br>
<a href="http://llvm.org/docs/GarbageCollection.html" target="_blank">http://llvm.org/docs/GarbageCollection.html</a>) , but I don't know its<br>
performance .<br>
<br>
Can you advice me to the best solution , between the first and the<br>
second solution ? does LLVM GC better than python's GC and other<br>
equivalents ?<br>
<br>
Thanks.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>