You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the FileStreamOptions were introduced it also contained the PreallocationSize in order to a preallocation of the file if the final size is known already at the beginning. Before I have always used SetLength which worked fine. My question now is, if I can safely use PreallocationSize instead of using SetLength?
Regarding the docs it says:
The initial allocation size in bytes for the file. A positive value is effective only when a regular file is being created or overwritten (Create or CreateNew). Negative values are not allowed. In other cases (including the default 0 value), it's ignored. This value is a hint and is not a strong guarantee. It is not supported on Web Assembly (WASM) and FreeBSD (the value is ignored). For Windows, Linux and macOS we will try to preallocate the disk space to fill the requested allocation size. If that turns out to be impossible, the operation is going to throw an exception. The final file length (EOF) will be determined by the number of bytes written to the file.
Obviously SetLength, nowadays calls into RandomAccess.SetLength and then into libSystem.Native where I'm currently not able to look into how it is implemented.
So what is the suggestions today? Using SetLength or PreallocationSize.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When the
FileStreamOptions
were introduced it also contained thePreallocationSize
in order to a preallocation of the file if the final size is known already at the beginning. Before I have always usedSetLength
which worked fine. My question now is, if I can safely usePreallocationSize
instead of usingSetLength
?Regarding the docs it says:
which makes me a little nervous because of "The value is a hint" and the "not supported" because none of these limitations have been shown in the docs reagrding SetLength (https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.setlength?view=net-6.0).
Obviously SetLength, nowadays calls into
RandomAccess.SetLength
and then intolibSystem.Native
where I'm currently not able to look into how it is implemented.So what is the suggestions today? Using
SetLength
orPreallocationSize
.Beta Was this translation helpful? Give feedback.
All reactions