Skip to content

Commit 6f06f6e

Browse files
committed
add remarks about encoded buffer size calculation
1 parent d779cfc commit 6f06f6e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Base32.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
using System;
77
using System.IO;
8+
using System.Runtime.Intrinsics.X86;
89
using System.Threading.Tasks;
10+
using static System.Runtime.InteropServices.JavaScript.JSType;
911

1012
namespace SimpleBase;
1113

@@ -115,6 +117,12 @@ public int GetSafeByteCountForDecoding(ReadOnlySpan<char> text)
115117
}
116118

117119
/// <inheritdoc/>
120+
///<remarks>
121+
///This formula overestimates the required size to the next multiplier of 8 characters
122+
///to leave space for the padding characters at the end. If this kind of generous
123+
///allocation is a problem, a different formula can be used with non-allocating encoding
124+
///functions like <see cref="TryEncode(ReadOnlySpan{byte}, Span{char}, out int)" />.
125+
///</remarks>
118126
public int GetSafeCharCountForEncoding(ReadOnlySpan<byte> buffer)
119127
{
120128
return (((buffer.Length - 1) / bitsPerChar) + 1) * bitsPerByte;

0 commit comments

Comments
 (0)