Esempio n. 1
0
        static Memory()
        {
            hHeap = SafeNativeMethods.HeapCreate(0, IntPtr.Zero, IntPtr.Zero);

            uint info = 2;

            try {
                // Enable the low-fragmentation heap (LFH)
                SafeNativeMethods.HeapSetInformation(hHeap,
                                                     NativeConstants.HeapCompatibilityInformation,
                                                     (void *)&info,
                                                     sizeof(uint));
            } catch (Exception) {
                // If that method isn't available, like on Win2K, don't worry about it.
            }

            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
        }
Esempio n. 2
0
        private static void CreateHeap()
        {
            hHeap = SafeNativeMethods.HeapCreate(0, UIntPtr.Zero, UIntPtr.Zero);

            if (hHeap == IntPtr.Zero)
            {
                int error = Marshal.GetLastWin32Error();
                throw new System.ComponentModel.Win32Exception(error, string.Format(CultureInfo.InvariantCulture, "HeapCreate returned NULL, LastError = {0}", error));
            }
            uint info = 2;

            try
            {
                // Enable the low-fragmentation heap (LFH)
                SafeNativeMethods.HeapSetInformation(hHeap,
                                                     NativeConstants.HeapCompatibilityInformation,
                                                     (void *)&info,
                                                     new UIntPtr(4UL));
            }
            catch (EntryPointNotFoundException)
            {
                // If that method isn't available, like on Win2K, don't worry about it.
            }
        }