If your buffer is immutable during the time of computation, you can use a 
(copying) seq, but you should pass to the compute proc an openarray or `ptr 
UncheckedArray` so there is no GC or copy involved.

This is an example of a decently fast data structure for finance: 
<https://github.com/mratsim/weave/blob/5034793/benchmarks/black_scholes/weave_black_scholes.nim#L36-L65>
    
    
    type
      OptionKind = enum
        Put
        Call
      
      OptionData[T: SomeFloat] = object
        spot: T     # Spot price
        strike: T   # Strike price
        riskfree: T # risk-free rate
        divrate: T  # dividend rate
        vol: T      # volatility
        expiry: T   # expiry to maturity or option expiration in years
                    # (1 year = 1.0, 6 months = 0.5)
        kind: OptionKind
        divvals: T  # Dividend values (not used in this test)
        dgrefval: T # DerivaGem reference value
      
      Context[T: SomeFloat] = object
        data: ptr UncheckedArray[OptionData[T]]
        prices: ptr UncheckedArray[T]
        numOptions: int
        numRuns: int
        
        otype: ptr UncheckedArray[OptionKind]
        spot: ptr UncheckedArray[T]
        strike: ptr UncheckedArray[T]
        riskFreeRate: ptr UncheckedArray[T]
        volatility: ptr UncheckedArray[T]
        expiry: ptr UncheckedArray[T]
        numErrors: int
    
    
    Run

Nowadays I would use `{.experimental: "views".}` and store openarrays but this 
was written a long time ago. 

Reply via email to