So, I am trying to write a new linked list in c# that will behave properly in an unsafe context so I can pass it off to a multithreaded process. Unfortunately, even though all I need is a constant size pointer, this is creating a circular dependency. I would rather not make this a class, and I'm not sure how that would behave in an unsafe context. I also don't think that the interface solution will work in my case as it is literally a pointer to itself. Also, when I try to write it it complains about some of the code being managed yet... how do I fix that? Here is the code snippet:
struct UnsafeLinkedListNode<T>
{
public T value;
unsafe public UnsafeLinkedListNode<T>* next;
unsafe public UnsafeLinkedListNode<T>* prev;
}
class UnsafeLinkedList<T>
{
unsafe public UnsafeLinkedListNode<T>* head = null;
unsafe public UnsafeLinkedListNode<T>* tail = null;
public ulong count;
public void AddAfter(T value)
{
UnsafeLinkedList<T> temp = new UnsafeLinkedList<T>();
temp.value = value;
AddAfter(temp);
}
public void AddAfter(UnsafeLinkedListNode<T>* value)
{
unsafe
{
if(head !=null)
{
value.prev = tail;
value.next = null;
tail.next = value;
count++;
}
else
{
value.next = null;
value.prev = null;
head = value;
tail = value;
count++;
}
}
}
}