Skip to content

Alternative architecture for smartptrs #7

Description

@planetis-m

To accommodate the use-cases specified in #5 (comment), here is my proposed alternative:

https://github.com/planetis-m/dumpster/blob/master/expsmarts.nim#L18-L30

type
  SharedPtr*[T] = object
    ## Shared ownership reference counting pointer.
    deleter*: Deleter[T]
    val*: ptr Payload[T]

proc `=destroy`*[T](p: var SharedPtr[T]) =
  if p.val != nil:
    if p.val.counter.load(Consume) == 0:
      `=destroy`(p.val.value)
      if p.deleter != nil:
        p.deleter(p.val[])
    else:
      atomicDec(p.val.counter)

Can the deleter field be removed somehow?
Every field must be exported, so that libraries can provide their implementations like this:

https://github.com/planetis-m/dumpster/blob/master/pools.nim#L24

Opinions? @arnetheduck, @timotheecour, @Araq

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions