public static void Free(UnsafeHashCollection *collection)
        {
            Assert.Check(collection->Entries.Dynamic);

            AllocHelper.Free(collection->Buckets);
            AllocHelper.Free(collection->Entries.Ptr);
        }
Exemplo n.º 2
0
        public static void Free(UnsafeBitSet *set)
        {
            // clear memory
            *set = default;

            // free memory
            AllocHelper.Free(set);
        }
        internal static void Free(UnsafeOrderedCollection *collection)
        {
            // free the buffer
            UnsafeBuffer.Free(&collection->Entries);

            // free collection header itself
            AllocHelper.Free(collection);
        }
Exemplo n.º 4
0
        public static void Free(UnsafeHashMap *set)
        {
            if (set->_collection.Entries.Dynamic)
            {
                UnsafeHashCollection.Free(&set->_collection);
            }

            AllocHelper.Free(set);
        }
Exemplo n.º 5
0
        public static void Free(UnsafeRingBuffer *ring)
        {
            Assert.Check(ring != null);

            // clear memory just in case
            *ring = default;

            // release ring memory
            AllocHelper.Free(ring);
        }
Exemplo n.º 6
0
        public static void Free(UnsafeOrderedSet *set)
        {
            if (set->_collection.Entries.Dynamic)
            {
                UnsafeBuffer.Free(&set->_collection.Entries);
            }

            // clear memory
            *set = default;

            // free it
            AllocHelper.Free(set);
        }
Exemplo n.º 7
0
        static void Expand(UnsafeHashCollection *collection)
        {
            Assert.Check(collection->Entries.Dynamic);

            var capacity = GetNextPrime(collection->Entries.Length);

            Assert.Check(capacity >= collection->Entries.Length);

            var newBuckets = (Entry **)AllocHelper.MallocAndClear(capacity * sizeof(Entry * *), sizeof(Entry * *));
            var newEntries = default(UnsafeBuffer);

            UnsafeBuffer.InitDynamic(&newEntries, capacity, collection->Entries.Stride);
            UnsafeBuffer.Copy(collection->Entries, 0, newEntries, 0, collection->Entries.Length);

            collection->FreeHead  = null;
            collection->FreeCount = 0;

            for (int i = collection->Entries.Length - 1; i >= 0; --i)
            {
                var entry = (Entry *)((byte *)newEntries.Ptr + (i * newEntries.Stride));
                if (entry->State == EntryState.Used)
                {
                    var bucketHash = entry->Hash % capacity;

                    // assign current entry in buckets as next
                    entry->Next = newBuckets[bucketHash];

                    // assign entry as new bucket head
                    newBuckets[bucketHash] = entry;
                }

                // entry is in free list
                else if (entry->State == EntryState.Free)
                {
                    // assign free list as next
                    entry->Next = collection->FreeHead;

                    // re-assign free list to entry
                    collection->FreeHead  = entry;
                    collection->FreeCount = collection->FreeCount + 1;
                }
            }

            // free old memory
            AllocHelper.Free(collection->Buckets);
            UnsafeBuffer.Free(&collection->Entries);

            // new storage
            collection->Buckets = newBuckets;
            collection->Entries = newEntries;
        }
Exemplo n.º 8
0
        public static void Free(UnsafeStack *stack)
        {
            Assert.Check(stack != null);

            // if this is a dynamic sized stack, we need to free the buffer by hand
            if (stack->_items.Dynamic)
            {
                UnsafeBuffer.Free(&stack->_items);
            }

            // clear stack memory just in case
            *stack = default;

            // free stack memory (if this is a fixed size stack, it frees the _items memory also)
            AllocHelper.Free(stack);
        }
Exemplo n.º 9
0
        public static void Free(UnsafeBuffer *buffer)
        {
            Assert.Check(buffer != null);

            if (buffer->Dynamic == false)
            {
                throw new InvalidOperationException("Can't free a fixed buffer");
            }

            // buffer ptr can't be null
            Assert.Check(buffer->Ptr != null);

            // free memory of ptr
            AllocHelper.Free(buffer->Ptr);

            // clear buffer itself
            *buffer = default;
        }
Exemplo n.º 10
0
        public static void Free(UnsafeQueue *queue)
        {
            if (queue == null)
            {
                return;
            }

            // not fixed, we need to free items separtely
            if (queue->_items.Dynamic)
            {
                UnsafeBuffer.Free(&queue->_items);
            }

            // clear queue memory (just in case)
            *queue = default;

            // free queue memory, if this is a fixed queue it frees the items memory at the same time
            AllocHelper.Free(queue);
        }
Exemplo n.º 11
0
        public static void Free(UnsafeHeapMax *heap)
        {
            if (heap == null)
            {
                return;
            }

            // free dynamic items separately
            if (heap->_items.Dynamic)
            {
                UnsafeBuffer.Free(&heap->_items);
            }

            // clear memory
            *heap = default;

            // free heap
            AllocHelper.Free(heap);
        }
Exemplo n.º 12
0
 public static void Free(UnsafeList *list)
 {
     AllocHelper.Free(list);
 }
Exemplo n.º 13
0
 public static void Free(UnsafeHashMap *map)
 {
     AllocHelper.Free(map->_collection.Buckets);
     AllocHelper.Free(map->_collection.FreeHead);
     UnsafeBuffer.Free(&map->_collection.Entries);
 }
Exemplo n.º 14
0
 public static void Free(UnsafeArray *array)
 {
     AllocHelper.Free(array);
 }