There is a [memowner bool in the 
type](https://github.com/numforge/laser/blob/990e59fffe50779cdef33aa0b8f22da19e1eb328/laser/tensor/datatypes.nim#L12-L30).
 If it's false, it will not deallocate memory when not referenced.
    
    
    const LASER_MAXRANK*{.intdefine.} = 6
    
    type DynamicStackArray*[T] = object
        data*: array[LASER_MAXRANK, T]
        len*: int
    
    type
      RawImmutableView*[T] = distinct ptr UncheckedArray[T]
      RawMutableView*[T] = distinct ptr UncheckedArray[T]
      
      Metadata* = DynamicStackArray[int]
      
      Tensor*[T] = object                    # Total stack: 128 bytes = 2 
cache-lines
        shape*: Metadata                     # 56 bytes
        strides*: Metadata                   # 56 bytes
        offset*: int                         # 8 bytes
        storage*: CpuStorage[T]              # 8 bytes
      
      CpuStorage*{.shallow.}[T] = ref object # Total heap: 25 bytes = 1 
cache-line
        when supportsCopyMem(T):
          raw_data*: ptr UncheckedArray[T]   # 8 bytes
          memalloc*: pointer                 # 8 bytes
          memowner*: bool                    # 1 byte
        else: # Tensors of strings, other ref types or non-trivial destructors
          raw_data*: seq[T]                  # 8 bytes (16 for seq v2 backed by 
destructors?)
    
    
    Run

Reply via email to