Esempio n. 1
0
        /// <summary>
        ///     Writes data to a reflexive, reallocating the original.
        /// </summary>
        /// <param name="entries">The entries to write.</param>
        /// <param name="oldCount">The old count.</param>
        /// <param name="oldAddress">The old address.</param>
        /// <param name="newCount">The number of entries to write.</param>
        /// <param name="layout">The layout of the data to write.</param>
        /// <param name="metaArea">The meta area of the cache file.</param>
        /// <param name="allocator">The cache file's meta allocator.</param>
        /// <param name="stream">The stream to manipulate.</param>
        /// <returns>The address of the new reflexive, or 0 if the entry list is empty and the reflexive was freed.</returns>
        public static uint WriteReflexive(IEnumerable <StructureValueCollection> entries, int oldCount, uint oldAddress,
                                          int newCount, StructureLayout layout, FileSegmentGroup metaArea, MetaAllocator allocator, IStream stream)
        {
            if (newCount == 0)
            {
                // Free the old reflexive and return
                if (oldCount > 0 && oldAddress != 0)
                {
                    allocator.Free(oldAddress, oldCount * layout.Size);
                }
                return(0);
            }

            uint newAddress = oldAddress;

            if (newCount != oldCount)
            {
                // Reallocate the reflexive
                int oldSize = oldCount * layout.Size;
                int newSize = newCount * layout.Size;
                if (oldCount > 0 && oldAddress != 0)
                {
                    newAddress = allocator.Reallocate(oldAddress, oldSize, newSize, stream);
                }
                else
                {
                    newAddress = allocator.Allocate(newSize, stream);
                }
            }

            // Write the new values
            WriteReflexive(entries.Take(newCount), newAddress, layout, metaArea, stream);
            return(newAddress);
        }
Esempio n. 2
0
        /// <summary>
        ///     Writes data to a block, reallocating the original.
        /// </summary>
        /// <param name="elements">The entries to write.</param>
        /// <param name="oldCount">The old count.</param>
        /// <param name="oldAddress">The old address.</param>
        /// <param name="newCount">The number of entries to write.</param>
        /// <param name="layout">The layout of the data to write.</param>
        /// <param name="metaArea">The meta area of the cache file.</param>
        /// <param name="allocator">The cache file's meta allocator.</param>
        /// <param name="stream">The stream to manipulate.</param>
        /// <returns>The address of the new tag block, or 0 if the entry list is empty and the tag block was freed.</returns>
        public static long WriteTagBlock(IEnumerable <StructureValueCollection> elements, int oldCount, long oldAddress,
                                         int newCount, StructureLayout layout, FileSegmentGroup metaArea, MetaAllocator allocator, IStream stream)
        {
            if (newCount == 0)
            {
                // Free the old block and return
                if (oldCount > 0 && oldAddress != 0)
                {
                    allocator.Free(oldAddress, oldCount * layout.Size);
                }
                return(0);
            }

            long newAddress = oldAddress;

            if (newCount != oldCount)
            {
                // Reallocate the block
                int oldSize = oldCount * layout.Size;
                int newSize = newCount * layout.Size;
                if (oldCount > 0 && oldAddress != 0)
                {
                    newAddress = allocator.Reallocate(oldAddress, oldSize, newSize, stream);
                }
                else
                {
                    newAddress = allocator.Allocate(newSize, stream);
                }
            }

            // Write the new values
            WriteTagBlock(elements.Take(newCount), newAddress, layout, metaArea, stream);
            return(newAddress);
        }
Esempio n. 3
0
        /// <summary>
        ///     Writes data to a reflexive, reallocating the original.
        /// </summary>
        /// <param name="entries">The entries to write.</param>
        /// <param name="oldCount">The old count.</param>
        /// <param name="oldAddress">The old address.</param>
        /// <param name="newCount">The number of entries to write.</param>
        /// <param name="layout">The layout of the data to write.</param>
        /// <param name="metaArea">The meta area of the cache file.</param>
        /// <param name="allocator">The cache file's meta allocator.</param>
        /// <param name="stream">The stream to manipulate.</param>
        /// <returns>The address of the new reflexive, or 0 if the entry list is empty and the reflexive was freed.</returns>
        public static uint WriteReflexive(IEnumerable<StructureValueCollection> entries, int oldCount, uint oldAddress,
			int newCount, StructureLayout layout, FileSegmentGroup metaArea, MetaAllocator allocator, IStream stream)
        {
            if (newCount == 0)
            {
                // Free the old reflexive and return
                if (oldCount > 0 && oldAddress != 0)
                    allocator.Free(oldAddress, oldCount*layout.Size);
                return 0;
            }

            uint newAddress = oldAddress;
            if (newCount != oldCount)
            {
                // Reallocate the reflexive
                int oldSize = oldCount*layout.Size;
                int newSize = newCount*layout.Size;
                if (oldCount > 0 && oldAddress != 0)
                    newAddress = allocator.Reallocate(oldAddress, oldSize, newSize, stream);
                else
                    newAddress = allocator.Allocate(newSize, stream);
            }

            // Write the new values
            WriteReflexive(entries.Take(newCount), newAddress, layout, metaArea, stream);
            return newAddress;
        }