예제 #1
0
        /** <inheritdoc /> */
        public override void Reallocate(int cap)
        {
            // Try doubling capacity to avoid excessive allocations.
            int doubledCap = ((PlatformMemoryUtils.Capacity(MemPtr) + 16) << 1) - 16;

            if (doubledCap > cap)
            {
                cap = doubledCap;
            }

            PlatformMemoryUtils.ReallocateUnpooled(MemPtr, cap);
        }
예제 #2
0
        /** <inheritdoc /> */
        public override void Reallocate(int cap)
        {
            // Try doubling capacity to avoid excessive allocations.
            int doubledCap = PlatformMemoryUtils.GetCapacity(Pointer) << 1;

            if (doubledCap > cap)
            {
                cap = doubledCap;
            }

            PlatformMemoryPool.Reallocate(Pointer, cap);
        }
예제 #3
0
        /** <inheritdoc /> */
        public override void Reallocate(int cap)
        {
            // Try doubling capacity to avoid excessive allocations.
            int doubledCap = PlatformMemoryUtils.Capacity(MemPtr) << 1;

            if (doubledCap > cap)
            {
                cap = doubledCap;
            }

            _pool.Reallocate(MemPtr, cap);
        }
예제 #4
0
        /// <summary>
        /// Create JVM.
        /// </summary>
        /// <returns>JVM.</returns>
        private static void *CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
        {
            var ggHome = IgniteHome.Resolve(cfg);

            var cp = Classpath.CreateClasspath(ggHome, cfg, false);

            var jvmOpts = GetMergedJvmOptions(cfg);

            var hasGgHome = !string.IsNullOrWhiteSpace(ggHome);

            var opts = new sbyte *[1 + jvmOpts.Count + (hasGgHome ? 1 : 0)];

            int idx = 0;

            opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp);

            if (hasGgHome)
            {
                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged("-DIGNITE_HOME=" + ggHome);
            }

            foreach (string cfgOpt in jvmOpts)
            {
                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt);
            }

            try
            {
                IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8);

                fixed(sbyte **opts0 = opts)
                {
                    PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8);
                }

                try
                {
                    return(UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer));
                }
                finally
                {
                    Marshal.FreeHGlobal(mem);
                }
            }
            finally
            {
                foreach (sbyte *opt in opts)
                {
                    Marshal.FreeHGlobal((IntPtr)opt);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Create JVM.
        /// </summary>
        /// <returns>JVM.</returns>
        private static void *CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
        {
            var cp = Classpath.CreateClasspath(cfg);

            var jvmOpts = GetMergedJvmOptions(cfg);

            var opts = new sbyte *[1 + jvmOpts.Count];

            int idx = 0;

            opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp);

            foreach (string cfgOpt in jvmOpts)
            {
                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt);
            }

            try
            {
                IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8);

                fixed(sbyte **opts0 = opts)
                {
                    PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8);
                }

                try
                {
                    return(UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer));
                }
                finally
                {
                    Marshal.FreeHGlobal(mem);
                }
            }
            finally
            {
                foreach (sbyte *opt in opts)
                {
                    Marshal.FreeHGlobal((IntPtr)opt);
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Unsafe memory copy routine.
 /// </summary>
 /// <param name="src">Source.</param>
 /// <param name="dest">Destination.</param>
 /// <param name="len">Length.</param>
 private static void CopyMemory(byte *src, byte *dest, int len)
 {
     PlatformMemoryUtils.CopyMemory(src, dest, len);
 }
예제 #7
0
 /** <inheritdoc /> */
 public override void Release()
 {
     PlatformMemoryUtils.ReleaseUnpooled(MemPtr);
 }