I'm exploring Nim a little more and as an exercise I'm trying to build my own GCed seq type. I wanted something like this:
type
Vector[T] = object
data: ref UncheckedArray[T]
len: int
cap: int
proc initVectorOfCap[T](cap: int): Vector[T] =
result.data = unsafeNew(sizeof(T) * cap)
result.len = 0
result.cap = cap
I thought this was fine but then reading the manual I saw that UncheckedArray cannot contain references. Is this true? There's anyway to implement my own GC allocated seq type that is safe?
I already saw that page. I wanted it to use the GC because I do not want it to copy the data when it's assigned. I want to be able to have multiple copies of it. My intent was for it to work like Go slices. Is there any way to accomplish it?
About the name, I know Vector is not that great :)