Procs
proc newSharedSeq[T](): SharedSeq[T]
-
Create a new SharedSeq of type T
The SharedSeq object itself is allocated in thread local memory and managed by the GC so that it can be garbage collected like any other stdlib data type. This means there is no need to explicitly call any dealloc or free function since it will happen automatically.
The contents, however, are allocated in shared memory so that they can be used across threads safely.
Care should be taken to make sure that once a SharedSeq object is shared with another thread, its address does not change. If it does, other threads will be accessing invalid memory.
All SharedSeq operations ensure that any changes are localized within shared memory and not thread local memory.
var ss1: SharedSeq[int] ss2 = newSharedSeq[string]() ss1 = newSharedSeq()
proc newSharedSeq[T](s: seq[T] | SharedSeq[T]): SharedSeq[T]
-
Create a new SharedSeq of type T and populate with the elements of provided seq or SharedSeq.
Each element of the resulting SharedSeq copied from the source and maintained in shared memory.
var ss1 = newSharedSeq(@[1, 2, 3])
proc clear[T](ss: var SharedSeq[T])
- Clear the contents of the SharedSeq
proc free[T](ss: var SharedSeq[T])
-
Free all memory associated with the SharedSeq
This is not required unless memory needs to be recovered before the SharedSeq goes out of scope.
proc toSequence[T](ss: SharedSeq[T]): seq[T]
-
Convert a SharedSeq into an stdlib seq
Resulting seq is a thread local copy
proc set[T](ss: var SharedSeq[T]; c: seq[T] | SharedSeq[T])
-
Repopulate SharedSeq data with contents of provided seq or SharedSeq
Old contents are released if present.
proc len[T](ss: SharedSeq[T]): Natural
- Return the number of elements in the SharedSeq
proc add[T](c: var seq[T]; ss: SharedSeq[T])
- Append the contents of a SharedSeq into a stdlib seq
proc add[T](ss: var SharedSeq[T]; c: T | seq[T] | SharedSeq[T])
- Append the element or all elements of seq or SharedSeq into a SharedSeq
proc delete[T](ss: var SharedSeq[T]; i: Natural)
- Delete the i'th element from the SharedSeq
proc del[T](ss: var SharedSeq[T]; i: Natural)
-
Delete the i'th element from the SharedSeq
This is not an optimized version like in the stdlib.
proc remove[T](ss: var SharedSeq[T]; s: T)
- Remove the first matching element from the SharedSeq
proc insert[T](ss: var SharedSeq[T]; item: T; i = 0.Natural)
- Insert element in the i'th position in the SharedSeq
proc pop[T](ss: var SharedSeq[T]): T
- Pop and return the last element of the SharedSeq
proc contains[T](ss: SharedSeq[T]; s: T): bool
- Search sequence and find element
proc `$`[T](ss: SharedSeq[T]): string
- Convert the SharedSeq into its string representation
proc `&`[T](ss: SharedSeq[T]; c: T | seq[T] | SharedSeq[T]): SharedSeq[T]
- Append SharedSeq with element or elements of seq or SharedSeq and return in a new SharedSeq
proc `&`[T](c: T | seq[T]; ss: SharedSeq[T]): SharedSeq[T]
- Return a new SharedSeq with element or elements of seq appended with contents of SharedSeq
proc `&=`[T](ss: var SharedSeq[T]; c: T | seq[T] | SharedSeq[T])
- Append element or elements of seq or SharedSeq to the SharedSeq
proc `=`[T](ss: var SharedSeq[T]; sn: SharedSeq[T])
proc `[]`[T](ss: var SharedSeq[T]; i: Natural): T
- Access the i'th element in SharedSeq
proc `[]=`[T](ss: var SharedSeq[T]; i: Natural; value: T)
- Set the i'th element in SharedSeq to value
proc `==`[T](ss: SharedSeq[T]; c: string | cstring | SharedString): bool
proc `==`[T](ss: SharedSeq[T]; c: (seq[T] | SharedSeq[T])): bool
- Compare SharedSeq contents with another seq or SharedSeq