Some checks failed
Publish NuGet Packages / publish (pull_request) Has been cancelled
Introduce a Roslyn analyzer to enforce unique ownership semantics for structs marked with the `[NonCopyable]` attribute. Added a corresponding code fix to resolve violations by suggesting the use of `Share()` or other ownership transfer methods. Key changes: - Added `StructCopyCodeAnalyzer` to detect invalid struct copies. - Implemented `StructCopyCodeFixProvider` to provide code fixes. - Created `Misaki.HighPerformance.Analyzer` and `CodeFixes` projects. - Added unit tests for the analyzer and code fixes. - Introduced `UniquePtr<T>` and `SharedPtr<T>` for pointer ownership. - Added a Visual Studio extension project and packaging support. - Updated `UnsafeUtility` to use `nint`/`nuint` for indices.
67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
//var threadCount = 8;
|
|
//var map = new ConcurrentSlotMap<int>();
|
|
|
|
//var barrier = new Barrier(threadCount);
|
|
|
|
//Parallel.For(0, threadCount, threadIndex =>
|
|
//{
|
|
// barrier.SignalAndWait();
|
|
// for (var i = 0; i < 1000; i++)
|
|
// {
|
|
// var id = map.Add(i + threadIndex * 1000, out var gen);
|
|
// if (i % 100 == 0)
|
|
// {
|
|
// map.Remove(id, gen);
|
|
// }
|
|
// }
|
|
//});
|
|
|
|
//Console.WriteLine($"Count should be {threadCount * 990}, actual: {map.Count}");
|
|
|
|
using Misaki.HighPerformance.LowLevel;
|
|
|
|
BenchmarkDotNet.Running.BenchmarkRunner.Run<Misaki.HighPerformance.Test.Benchmark.CollectionBenchmark>();
|
|
|
|
//using Misaki.HighPerformance.LowLevel.Buffer;
|
|
//using Misaki.HighPerformance.LowLevel.Collections;
|
|
//using Misaki.HighPerformance.LowLevel.Utilities;
|
|
|
|
//using (AllocationManager.CreateStackScope())
|
|
//{
|
|
// var array = new UnsafeArray<int>(10, Allocator.Stack);
|
|
// for (var i = 0; i < array.Count; i++)
|
|
// {
|
|
// array[i] = i;
|
|
// }
|
|
|
|
// foreach (var item in array.AsSpan())
|
|
// {
|
|
// Console.WriteLine(item);
|
|
// }
|
|
//}
|
|
|
|
//var arr1 = new Misaki.HighPerformance.LowLevel.Collections.UnsafeArray<int>(10, Misaki.HighPerformance.LowLevel.Buffer.Allocator.Persistent);
|
|
//var arr2 = arr1;
|
|
|
|
//arr1.Dispose();
|
|
//try
|
|
//{
|
|
// arr2[0] = 42; // This should throw an exception because arr1 has been disposed.
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// Console.WriteLine($"Caught expected exception: {ex.Message}");
|
|
//}
|
|
//arr2.Dispose(); // This should not cause a double free error because of safe handle.
|
|
|
|
var a = new UniquePtr<MyStruct>();
|
|
unsafe
|
|
{
|
|
var b = a.Share();
|
|
b.Get()->Value = 42;
|
|
}
|
|
|
|
internal struct MyStruct
|
|
{
|
|
public int Value;
|
|
} |