7 ms·
I don't know of any language that has pointers and a GC. Are there any? C# lets you use pointers but only if you tell the GC to not move your object and promise
by city41 13y ago
I don't know of any language that has pointers and a GC. Are there any? C# lets you use pointers but only if you tell the GC to not move your object and promise to behave.
- octo_t 13y agoOptional GC[1] in a language like C++, and Rust has pointers with task-local GC [1] - http://en.wikipedia.org/wiki/Boehm_GC http://en.wikipedia.org/wiki/Boehm_GC
- jballanc 13y agoThe Boehm–Demers–Weiser garbage collector is a fairly famous implementation of a GC for vanilla C, pointers and all: http://en.wikipedia.org/wiki/Boehm_garbage_collector http://en.wikipedia.org/wiki/Boehm_garbage_collector
- city41 13y agoYeah I'm aware of optional GCs. What I meant was languages that ship with a GC as standard and also have pointers. In the case of Boehm, since you choose to bring it in yourself, it's up to you to make sure you don't abuse it.
- jballanc 13y agoWell, pretty much any language with a GC can abuse the GC, regardless of whether it's optional or designed in from the start. It just happens to be a lot harder to abuse a GC than to forget to free/delete something.
- Scaevolus 13y agoYou can have a GC without compaction. Go has a GC and pointers, including internal pointers (e.g. to a field of a struct). Its GC started out fully conservative, then precise for the heap and conservative for the stack, and future versions will be fully precise.
- cwzwarich 13y agoSome languages in the Wirth family have pointers and GC, e.g. Modula-3. It has a module-level notion of safety, so that modules using potentially unsafe pointer manipulation are marked as unsafe and break runtime safety guarantees. It also doesn't guarantee that all pointers will be roots for GC.
- nicky0 13y agoObjective-C has pointers and a GC.
- wsc981 13y ago> "I don't know of any language that has pointers and a GC. Are there any?" Objective-C used to have a garbage collector, though (at least with regards to iOS) Apple removed this capability with the introduction or ARC. On the following URL is some discussion on the Objective-C garbage collector: http://cocoasamurai.blogspot.nl/2010/12/objective-c-memory-management-garbage.html http://cocoasamurai.blogspot.nl/2010/12/objective-c-memory-m...
- betterunix 13y agoOCaml, though in a very restricted sense: http://www.cs.cornell.edu/courses/cs3110/2011sp/recitations/rec10.htm http://www.cs.cornell.edu/courses/cs3110/2011sp/recitations/...
- pjmlp 13y ago> I don't know of any language that has pointers and a GC. Are there any? C# lets you use pointers but only if you tell the GC to not move your object and promise to behave Oberon, Oberon-2 allows you to use no-GC pointers via the SYSTEM package. Active Oberon additionally adds syntax support for untraced pointers. Modula-3 has unsafe modules which allow you to use untraced pointers. D has unsafe pointers in system blocks. Ada and C++11 have support for optional GC defined on the language standard. However so far, there isn't any compiler vendor that really offers them. In Java you can do a bit of dirty pointer tricks via the com.sun.unsafe package, but it is Oracle's VM specific. Although there are plans to make it part of the official library after Java 8.
- bitwize 13y agoVarious Lisp dialects over the years have supported the use of locatives, or pointer-like objects. In general, objects which can be moved or copied around by the runtime behind the programmer's back cannot have indefinite-extent hardware-address pointers taken directly into them. This includes objects managed by most halfway-decent garbage collectors (which tend to be implemented as stop-and-copy, not mark-and-sweep), but also includes such things as drawing surfaces in SDL and DirectDraw. Many runtimes take the C# approach -- provide a memory locking operation that fixes the object in memory while you do some pointer stuff on it and a dual unlocking operation that releases the object so it can be kicked around by the runtime again.