MemoryCompressor

02/03/2013 09:40 LordGragen.#1
hey guys, so today i am going to share something with you guys that i thow it might be helpful,

this is MemoryCompressor, i found this in my old source that i was using very long time ago.

here it is.

Code:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace COServer
{

    public class MemoryCompressor
    {

        internal class Native
        {

            // API Windows
            [DllImport("kernel32")]
            public static extern IntPtr OpenProcess(UInt32 dwAccess, Int32 dwDesiredAccess, UInt32 dwPID);

            [DllImport("psapi")]
            public static extern Int32 EmptyWorkingSet(IntPtr dwObject);

            [DllImport("kernel32")]
            public static extern Int32 CloseHandle(IntPtr dwObject);

            internal static unsafe void memcpy(byte* buffer, byte* ptr, int p)
            {
                throw new NotImplementedException();
            }
        }

        private uint m_ProcessId = 0;

        public MemoryCompressor()
        {
            m_ProcessId = (uint)Process.GetCurrentProcess().Id;
        }

        public void Optimize()
        {
            if (m_ProcessId != 0)
            {
                IntPtr Handle = Native.OpenProcess((uint)0x1F0FFF, 1, m_ProcessId);
                Native.EmptyWorkingSet(Handle);
                Native.CloseHandle(Handle);
            }
            else
                throw new Exception("MeomoryCompressor::Optimize() -> The process Id can't be equal to zero!");
        }

        public void Close()
        {
            m_ProcessId = 0;
        }
    }
} #credit "i dont know his name but credit to who ever made it"


this might not work with you or dont help allot, but it helped me allot for sure,

NOTE: i was reading on google today that MemoryCompressor might not be a good idea sometimes to use it on project like this, they might hurt the server but i dont know if that it fully true, so yah.


edit (1:11Am 2/3/2013)

they told me that this is not a good way,

#request close, but if you still need this feel free to take it maybe you can make something better out of it.
02/03/2013 15:52 CptSky#2
I made this thing based on an AutoIt application. Although it works, it should never be used with a program that requires high efficiency as a server.

Also, as a side note, the psapi dll no longer contains the required function which has been moved in kernel32 since Vista.

Btw. I never though it would surface :p
04/10/2013 16:51 marcbacor6666#3
can u remake it and make it work in any 5535+ public source?
04/11/2013 09:20 Spirited#4
Quote:
Originally Posted by marcbacor6666 View Post
can u remake it and make it work in any 5535+ public source?
.... The code snippet above is universal ... for absolutely any process ever created in a modern Windows machine. Don't be lame, read the 5 lines of code. There are absolutely no excuses because you can even google each line and figure out what this does.

PS: You shouldn't even be using this code. You didn't read what CptSky said about it either. Read, it helps :).
04/11/2013 17:23 marcbacor6666#5
ok ^^
04/12/2013 18:57 shadowman123#6
Quote:
Originally Posted by CptSky View Post
I made this thing based on an AutoIt application. Although it works, it should never be used with a program that requires high efficiency as a server.
WHY ?
04/12/2013 19:20 Super Aids#7
Quote:
Originally Posted by shadowman123 View Post
WHY ?
Read this:
[Only registered and activated users can see links. Click Here To Register...]
04/12/2013 20:26 littlechris95#8
It was nothing to do and did a program based on this code.

[Only registered and activated users can see links. Click Here To Register...]

Download Link: [Only registered and activated users can see links. Click Here To Register...]