Jump to content

Error allocating memory in my script


tom13
 Share

Recommended Posts

Hi,

I made a script with the help of some premade functions that will first get a list of all processes, then terminate all but explorer and the autoit exe, then recover and defrag memory and then launch the game World of Warcraft. I made this because it solves my lag issues and gives the "reboot feeling", in short it makes me run World of Warcraft alot smoother.

The code:

;Options START
$wowdir = "C:\Program Files\World of Warcraft\WoW.exe"
$wowtitle = "World of Warcraft"
$explorer = "explorer.exe"
;Options END

;Functions START
Func _MemDefrag()
    $mem = MemGetStats()
    If @OSTYPE == "WIN32_NT" Then
        $a = DllStructCreate("char[" & $mem[1] * 1024 & "]")
        Sleep(7500)
        $a = ""
    ElseIf @OSTYPE == "WIN32_WINDOWS" Then
        $a = DllStructCreate("char[" & ($mem[1] * 512) & "]")
        $a2 = DllStructCreate("char[" & ($mem[1] * 512) & "]")
        Sleep(7500)
        $a = ""
        $a2 = ""
    EndIf
EndFunc

Func _MemRecover()
    $list = ProcessList()
    For $i = 1 To $list[0][0]
        If StringInStr($list[$i][0], "csrss") > 0 Or StringInStr($list[$i][0], "smss") > 0 Or StringInStr($list[$i][0], "winlogon") > 0 Or StringInStr($list[$i][0], "lsass") > 0 Then ContinueLoop
        ntmem($list[$i][1])
    Next
EndFunc

Func ntmem($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
EndFunc
;Functions END

SoundPlay(@WindowsDir & "\media\chimes.wav",1)
$processlist = ProcessList()
for $i = 1 to $processlist[0][0]
  If $processlist[$i][0] <> $explorer AND $processlist[$i][1] <> @AutoItPID Then
  ProcessClose($processlist[$i][0])
  EndIf
next

_MemRecover()
_MemDefrag()

Run($wowdir)
WinWaitActive($wowtitle)
SoundPlay(@WindowsDir & "\media\tada.wav",1)
Exit

Now my problem is that when it is going to defrag the memory it gives the error "error allocating memory", anyone knows how I can solve this? By the way feel free to use/edit or whatever this code if you can use it :)

Link to comment
Share on other sites

If you have to reboot to reduce lag I think defragmenting your memory should be the last thing you have to worry about.

-Run msconfig and remove unnecessary startup items, or better yet use Nirsoft StartupRun http://www.nirsoft.net/utils/strun.html

-Disable Windows Automatic Updates as these will download whenever they feel like

-Run Nirsoft CurrPorts http://www.nirsoft.net/utils/cports.html with no programs open to make sure there aren't any mysterious programs making outside connections

-Scan for spyware with Spybot & Adaware

You really don't want kill every process except explorer.exe, just attempting to kill certain services can cause your system to hang.

Link to comment
Share on other sites

If you have to reboot to reduce lag I think defragmenting your memory should be the last thing you have to worry about.

-Run msconfig and remove unnecessary startup items, or better yet use Nirsoft StartupRun http://www.nirsoft.net/utils/strun.html

-Disable Windows Automatic Updates as these will download whenever they feel like

-Run Nirsoft CurrPorts http://www.nirsoft.net/utils/cports.html with no programs open to make sure there aren't any mysterious programs making outside connections

-Scan for spyware with Spybot & Adaware

You really don't want kill every process except explorer.exe, just attempting to kill certain services can cause your system to hang.

Thanks for your time but this isn't really helping me with solving my problem. Besides, I do want to run all those "unnecessary" programs at startup as I do more things then playing a game. Usually I do need those programs to startup at windows start.

Link to comment
Share on other sites

Is it just me. :) .... Or could it be that you try to allocate to much memory?

That said, Mark Russinovich claims that you can't defragment memory. I'm not saying that he is right. So go figure for yourself. Just search for "The Memory Optimization Hoax"

Link to comment
Share on other sites

Is it just me. :) .... Or could it be that you try to allocate to much memory?

That said, Mark Russinovich claims that you can't defragment memory. I'm not saying that he is right. So go figure for yourself. Just search for "The Memory Optimization Hoax"

hmm I have 2GB ram, is that a problem?

Link to comment
Share on other sites

Dude I have 2 gigs of ram and I can run Oblivion and Photoshop at the same time. World of Warcraft doesn't take more resources than either. Just look at the system requirements:

World of Warcraft

Windows® System 2000/XP OS:

  • Intel Pentium® IV 1.5 GHz or AMD XP 1500+ MHz
  • 1024 MB RAM
  • 64 MB 3D graphics card with Hardware Transform and Lighting, such as NVIDIA® GeForce FX 5700 class card or above
  • Broadband Internet connection
  • Two-button scroll-wheel mouse
Oblivion

  • 3 Ghz Intel Pentium 4 or equivalent processor
  • 1 GB System RAM
  • ATI X800 series, NVIDIA GeForce 6800 series, or higher video card
What are your system specs?

For comparison I run a Q6600 on an Abit IP35-Pro with 2 GB Corsair Dominator 1066 and an XFX 7900 GT

EDIT: BTW I've never played WoW but if you aren't lagging when you first start your system, then I doubt there is anything limiting you in terms of hardware

Edited by weaponx
Link to comment
Share on other sites

  • 1 month later...

Tom13, I know it may be a bit late in the day but I've just solved your problem with the memory allocation error :P

I was also working on a similar pre-game free-as-much-resources-as-possible routine and hit the same problem, but I soon solved it by moving the RAM defrag routine out to a seperate AutoIT executable and then calling that with the run command after killing selected tasks and stopping a few services.

Here's the defrag code (adapted from MrBond007 (Baki) & Picasso (Fida Florian) Memory Fusion script)

CODE

#Include <Constants.au3>

Dim $mem = MemGetStats()

$mem = MemGetStats()

ClipPut("")

If @OSTYPE == "WIN32_WINDOWS" Then

$dAtastruct = DllStructCreate("char[" & ($mem[1] * 512) & "]")

$dAtastruct2 = DllStructCreate("char[" & ($mem[1] * 512) & "]")

Sleep(7500)

$dAtastruct = ""

$dAtastruct2 = ""

ElseIf @OSTYPE == "WIN32_NT" Then

If @OSVersion == "WIN_VISTA" Then

$dAtastruct = DllStructCreate("char[" & $mem[1] * 768 & "]")

Sleep(7500)

$dAtastruct = ""

Else

$dAtastruct = DllStructCreate("char[" & $mem[1] * 1024 & "]")

Sleep(7500)

$dAtastruct = ""

EndIf

EndIf

EnvUpdate()

$mem = MemGetStats()

Msgbox(0,"RAM Defrag","Free RAM is now: " & Int($mem[2] / 1024) & " MB" )

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...