I am going to create a permanent collection (lists or another) in C #, but I can not understand a good API.
I use persistent in the Clojure sense : a constant list is a list that behaves as if it has value semantics instead of referential semantics, but does not bear the overhead of copying large value types. Persistent collections use copy-on-write to share internal structure. Pseudocode:
l1 = PersistentList()
l1.add("foo")
l1.add("bar")
l2 = l1
l1.add("baz")
print(l1) # ==> ["foo", "bar", "baz"]
print(l2) # ==> ["foo", "bar"]
# l1 and l2 share a common structure of ["foo", "bar"] to save memory
Clojure uses such data structures, but in addition in Clojure all data structures are immutable. There is some overhead in performing all copy-to-write operations, so Clojure provides a workaround in the form of transient datastructures that you can use if you are sure that you are not using anyone else. If you have a single link to a data structure, why not reinstall it directly, instead of going through all the copying overhead.
( , Clojure ). refcount 1, , . , - , , -- .
API refcounting, API , , , COW'ed, API , , COW .
# structs, . , , incref()/decf() .
- #, API?
:
- , API. Clojure Java.
- , , , COW'ed . refcounting , COWing, , -, API.