Memory safe and coroutines are the focus of D.
IGotD-
nise at nise.com
Sun Oct 16 22:51:58 UTC 2022
On Sunday, 16 October 2022 at 22:07:59 UTC, Per Nordlöw wrote:
>
> Can you give elaborate or give references on the topic of using
> managed pointers that do ARC? Are some bits of the address used
> to store the reference count. What about other languages like
> Java and C#? Do they also pack flags into the adresses?
>
> I find lots of articles on managed pointers in Swift like
> https://www.vadimbulavin.com/swift-pointers-overview-unsafe-buffer-raw-and-managed-pointers/ but no information on how they are actually encoded on the bit-level.
Not that easy to find information about the memory layout of the
Swift data structures. What I've understood in this page
https://academy.realm.io/posts/goto-mike-ash-exploring-swift-memory-layout/
is that the reference count (which is called retain count in
Swift world) is stored in the beginning of the class structure
together with the members, two counters, one strong count and one
weak count. It's really the most simple way to store it as only
classes have reference counting in Swift.
Swift has a bunch of unsafe raw pointers but one that is
interesting the unmanaged wrapper. With that one if you wrap your
class in a unmanaged wrapper then it basically becomes a manually
reference counted class. This can be useful if you have a code
section you know the class will be alive and you can do away with
all the increase/decrease of the reference count (which is also
atomic).
Reference counting really adds to the instrumentation of the
code, like the unmanaged wrapper, you have to deal with
strong/weak references. Swift is talking about adding movable
types, borrow/take modifiers to reduce the counting.
https://forums.swift.org/t/borrow-and-take-parameter-ownership-modifiers/59581
It's not all glamour with ARC and it has its downsides as well.
More information about the Digitalmars-d
mailing list