Replies: 3 comments
-
I don't think this is true. For example, there's the All the actual vector implementations allow re-using of memory using one of the constructors, for example DenseVector(DenseVectorStorage<double> storage)
DenseVector(double[] storage) Alternatively, there's a static helper class with generic methods CreateVector.WithStorage<T>(VectorStorage<T> storage)
CreateVector.Dense<T>(DenseVectorStorage<T> storage)
CreateVector.Dense<T>(T[] array) which should also re-use the already allocated memory (haven't checked that, though). |
Beta Was this translation helpful? Give feedback.
-
Sorry I should have been more thorough. I have only been working with sparse implementations, which does not seem to provide anyway to reuse arrays. At the very least, it would be good to allow using ArrayPool to prevent new allocations. |
Beta Was this translation helpful? Give feedback.
-
Ok, I think for sparse vectors, it would be a good addition to have a constructor that takes the storage arrays. What length do the vectors have? Would using dense vectors be an option? |
Beta Was this translation helpful? Give feedback.
-
I am creating multiple very large vectors based on memory that has already been allocated. Currently, the storage classes will always create a new array and copy the data over when creating a new vector. The GC eventually cleans everything up as expected when the vectors are released. However, this does create a massive churn on memory. There doesn't appear to be a way to re-use that memory. Am I missing something? Would you be open to a PR that updates the storage related classes to allow for that? If so, do you have any guidance or gotchas that I should be aware of before I get too far down any particular path? In a best case scenario, I could just take advantage of the existing arrays that are already allocated without allocating anything new. Worst case, it would at least use
ArrayPool.Shared
to allocate the arrays so that it wasn't having to re-allocate a new array every time.Beta Was this translation helpful? Give feedback.
All reactions