Пример #1
0
        /// <summary>
        /// Returns a pointer to a structure, allocated in unmanaged memory.
        /// </summary>
        /// <typeparam name="T">A ref-free type.</typeparam>
        /// <param name="mps">The pointer holder.</param>
        /// <returns></returns>
        public unsafe static T *Reserve <T>(out MarshalSlot mps) where T : unmanaged
        {
            mps = new MarshalSlot(sizeof(T));
            var p = (T *)mps.slotPtr.ToPointer();

            return(p);
        }
Пример #2
0
        /// <summary>
        /// Store an unmanaged structure which has no managed references.
        /// </summary>
        /// <typeparam name="T">Unmanaged structure type</typeparam>
        /// <param name="str">The value</param>
        /// <returns></returns>
        public unsafe static MarshalSlot Store <T>(T str) where T : unmanaged
        {
            var mps = new MarshalSlot(sizeof(T));
            var p   = (T *)mps.slotPtr.ToPointer();

            *p = str;
            return(mps);
        }
Пример #3
0
        /// <summary>
        /// Only the size argument is used.
        /// </summary>
        /// <param name="size">The size in bytes.</param>
        /// <param name="tries">Ignored</param>
        /// <param name="awaitMS">Ignored</param>
        /// <returns>Either a HeapSlot or a MarshalSlot</returns>
        public MemoryFragment AllocFragment(int size, int tries = 0, int awaitMS = 10)
        {
            MemoryFragment f = null;

            if (allocateNativeHeapSlots)
            {
                f = new HeapSlot(size);
            }
            else
            {
                f = new MarshalSlot(size);
            }

            return(f);
        }