New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add newSeqUninitialized, closes #6401 #6402
Conversation
33de4ec
to
1d4f8f8
Compare
Doing some test, this implementation seems to work fine with small seqs, however huge seqs is not working: Working example: var a = newSeqUninitialized[int](10)
echo a[^1] Failing example: var a = newSeqUninitialized[int](1000000)
echo a[^1]
I don't know why, its like the newSeqOfCap doesn't actually create a seq with the desired cap. @Araq Can you help me on this? |
1d4f8f8
to
73bb9dc
Compare
I've created another proc in system to see if this was true. proc getCap*[T](s: seq[T]): int =
var s = cast[PGenericSeq](s)
return s.reserved My test case: var a = newSeqOfCap[int](10)
echo a.getCap() The test case outputs 0, either my method is wrong, or |
Have you actually seen noInit pragma in the nim language manual? https://nim-lang.org/docs/manual.html |
I don't think |
Why did you close this? |
No interest by the upstream having this as a new core function, as this also achievable by using |
@edubart "no interest by the upstream" are you sure? |
quote
I'm sure |
what's the use case for this? IMO, |
Filling a huge seq (GBs of bytes length) non contiguously, fastly without double initialization, and also in parallel with OpenMP (we can't use add in parallel) , such as in machine learning tasks in https://github.com/mratsim/Arraymancer. |
FYI I'm fine with this being closed. |
Pity, I find |
Indeed, Araq had to tell me a few times to become clear that this could be achieved by using |
Same reasoning for me, I always thought this just wasn't possible. |
@edubart maybe make a PR for docs then ? :) |
Thinking about it, this is arguably a |
I guess we need a PR for setLenUninitialized then ;) |
This is useful as mentioned in the issue #6401
Note that this is only implemented for seq of numbers. I'm not sure if this is the correct implementation, however testing using this method I do see random numbers when initializing and no zeros anymore.
Please review.