Hallo
Ich bin gerade dabei eine Datenbank auszulesen.
In dieser sind mehr als Int32.Max Tupel enthalten die ich einmal Komplett reinladen müsste in ein Array.
Ich weiß es gibt limits womit ich ein Teil der Tupel laden könnte und dann den Rest, aber die Tupel basieren aufeinfander und müssen im Ganzen gesehen werden.
Was ich im Internet gefunden habe ist - gcAllowVeryLargeObjects - aber ich hab keine Ahnung wie die Eigenschaft in dotnet Core setze O.o
Kann mir da wer helfen?
EDIT:
Source - Code
Spoiler anzeigen
Ich bin gerade dabei eine Datenbank auszulesen.
In dieser sind mehr als Int32.Max Tupel enthalten die ich einmal Komplett reinladen müsste in ein Array.
Ich weiß es gibt limits womit ich ein Teil der Tupel laden könnte und dann den Rest, aber die Tupel basieren aufeinfander und müssen im Ganzen gesehen werden.
Was ich im Internet gefunden habe ist - gcAllowVeryLargeObjects - aber ich hab keine Ahnung wie die Eigenschaft in dotnet Core setze O.o
Kann mir da wer helfen?
EDIT:
Source - Code
C#-Quellcode
- unsafe class BigList<T> : IDisposable
- {
- private const int BASE_INIT_CAP = 4;
- private delegate IntPtr InternalAllocDelegate(object obj, GCHandleType gCHandleType);
- private delegate void InternalFreeDelegate(IntPtr handle);
- private delegate object InternalGetDelegate(IntPtr handle);
- private static readonly InternalAllocDelegate InternalAlloc = GetMethodOf<InternalAllocDelegate>(typeof(GCHandle), "InternalAlloc", BindingFlags.NonPublic | BindingFlags.Static);
- private static readonly InternalFreeDelegate InternalFree = GetMethodOf<InternalFreeDelegate>(typeof(GCHandle), "InternalFree", BindingFlags.NonPublic | BindingFlags.Static);
- private static readonly InternalGetDelegate InternalGet = GetMethodOf<InternalGetDelegate>(typeof(GCHandle), "InternalGet", BindingFlags.NonPublic | BindingFlags.Static);
- public T this[long index] {
- get => (T)InternalGet(GetHandleValue(ref *((IntPtr*)_internalMem.ToPointer() + index)));
- set {
- IntPtr* elementPtr = ((IntPtr*)_internalMem.ToPointer() + index);
- if (*elementPtr != IntPtr.Zero)
- {
- InternalFree(*elementPtr);
- }
- *elementPtr = SetIsPinned(InternalAlloc(value, GCHandleType.Pinned));
- }
- }
- private long _capacity;
- private IntPtr _internalMem;
- public long Count;
- public BigList() : this(BASE_INIT_CAP) { }
- public BigList(long baseCapacity)
- {
- _capacity = baseCapacity * IntPtr.Size;
- _internalMem = Marshal.AllocHGlobal(new IntPtr(_capacity));
- Count = 0;
- }
- public long AddItems(T element)
- {
- if (Count * IntPtr.Size == _capacity)
- {
- _capacity *= 2;
- IntPtr memAlloc = Marshal.AllocHGlobal(new IntPtr(_capacity));
- Buffer.MemoryCopy(_internalMem.ToPointer(), memAlloc.ToPointer(), _capacity, Count * IntPtr.Size);
- Marshal.FreeHGlobal(_internalMem);
- _internalMem = memAlloc;
- }
- *(((IntPtr*)_internalMem) + Count) = SetIsPinned(InternalAlloc(element, GCHandleType.Pinned));
- return Count++;
- }
- internal IntPtr GetHandleValue(ref IntPtr handle)
- {
- #if WIN32
- return new IntPtr(((int)handle) & ~1);
- #else
- return new IntPtr(((long)handle) & ~1L);
- #endif
- }
- internal bool IsPinned(ref IntPtr handle)
- {
- #if WIN32
- return (((int)handle) & 1) != 0;
- #else
- return (((long)handle) & 1) != 0;
- #endif
- }
- internal IntPtr SetIsPinned(IntPtr handle)
- {
- #if WIN32
- return new IntPtr(((int)handle) | 1);
- #else
- return new IntPtr(((long)handle) | 1L);
- #endif
- }
- ~BigList()
- {
- Dispose(false);
- }
- bool isDisposed;
- public void Dispose(bool dispose)
- {
- if (!isDisposed)
- {
- isDisposed = true;
- if (dispose)
- {
- for (int iElement = 0; iElement < Count; iElement++)
- {
- InternalFree(GetHandleValue(ref *((IntPtr*)_internalMem + iElement)));
- }
- }
- Marshal.FreeHGlobal(_internalMem);
- }
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- private static TOut GetMethodOf<TOut>(Type type, string methodeName, BindingFlags bindingFlags) where TOut : Delegate
- => (TOut)Delegate.CreateDelegate(typeof(TOut), type.GetMethod(methodeName, bindingFlags));
- }
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Facebamm“ ()