Skip to content

Commit f99c946

Browse files
committed
Add warnings for ref values. Fixes #1.
1 parent 649123b commit f99c946

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/Berrysoft.Unsafe/ByReference.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public readonly unsafe struct ByReference<T>
1616
private readonly void* _ptr;
1717
/// <summary>
1818
/// Initialize a <see cref="ByReference{T}"/> with a <typeparamref name="T"/> reference.
19+
/// Note: the storage of value should be pinned.
1920
/// </summary>
2021
/// <param name="value">The reference.</param>
2122
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Berrysoft.Unsafe/Pointer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public Pointer(IntPtr ptr)
3838
}
3939
/// <summary>
4040
/// Initialize a <see cref="Pointer{T}"/> with a <typeparamref name="T"/> reference.
41+
/// Note: the storage of value should be pinned.
4142
/// </summary>
4243
/// <param name="ptr">The reference.</param>
4344
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Berrysoft.Unsafe/UnsafeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public unsafe static class UnsafeMethods
1818
public static int GetSize<T>() => SizeOf<T>();
1919
/// <summary>
2020
/// Get a <see cref="Pointer{T}"/> with a <typeparamref name="T"/> reference.
21+
/// Note: the storage of value should be pinned.
2122
/// </summary>
2223
/// <typeparam name="T">Type of the pointer pointed to.</typeparam>
2324
/// <param name="value">The reference.</param>
@@ -47,6 +48,7 @@ public static Pointer<char> PointerOf(string str)
4748
}
4849
/// <summary>
4950
/// Get a <see cref="Unsafe.ByReference{T}"/> with a <typeparamref name="T"/> reference.
51+
/// Note: the storage of value should be pinned.
5052
/// </summary>
5153
/// <typeparam name="T">Type of the pointer pointed to.</typeparam>
5254
/// <param name="value">The reference.</param>
@@ -55,6 +57,7 @@ public static Pointer<char> PointerOf(string str)
5557
public static ByReference<T> ByReference<T>(ref T value) => new ByReference<T>(ref value);
5658
/// <summary>
5759
/// Get a <see cref="Unsafe.ByReference{T}"/> with a readonly <typeparamref name="T"/> reference.
60+
/// Note: the storage of value should be pinned.
5861
/// </summary>
5962
/// <typeparam name="T">Type of the pointer pointed to.</typeparam>
6063
/// <param name="value">The reference.</param>

0 commit comments

Comments
 (0)