/** <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); }
/** <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); }
/** <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); }
/// <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); } } }
/// <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); } } }
/// <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); }
/** <inheritdoc /> */ public override void Release() { PlatformMemoryUtils.ReleaseUnpooled(MemPtr); }