WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Error Codes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

1588 Unable to Allocate or Lock Memory


Question 1:

My program gives this error message inside my UDF IsFileOrDir: 1588 unable to allocate or lock memory

On line 18 of routine "IsFileOrDir"

Do you know what type of error is it and how to repair the program?

Answer:

Your script is attempting to use more virtual memory than Windows allows any process to use so you need to use less memory. Without knowing more about the requirements for you script any suggestions regarding changing it are simply a shot in the dark. But if you are collecting file or folder paths by scanning the file system, using the 'File & Folder Finder' extender (hate that name) would be one solution. The F&FF extender can be found as one of two extenders in the File Search extender download at

http://www.winbatch.com/download.html


Question 2:

These UDF are called many time they seem to work well then I get the following error any ideas
"1588: Unable to allocate or Lock memory" on line 27 BinaryReplace(bb, Old, new, @FALSE) 

using: WinBatch Studio 2006A WIL Version: 5.10aej

:UDFUDS
#DefineFunction standardedits(text, computername, username, rundate, humandate, machinedate, extracttime, today)
text = StrReplaceNC(text, "#computername#", computername)
text = StrReplaceNC(text, "#username#", username)
text = StrReplaceNC(text, "#rundate#", rundate)
text = StrReplaceNC(text, "#humandate#", humandate)
text = StrReplaceNC(text, "#machinedate#", machinedate)
text = StrReplaceNC(text, "#extracttime#", extracttime)
text = StrReplaceNC(text, "#today#", today)
Return(text)

#EndFunction

#DefineFunction StrReplaceNC(DaString,old,new)
len = strlen(DaString)
oldlen = strlen(old)
newlen = strlen(new)
bbsize = len

If newlen>oldlen
count = 0
i = 1

While @True
i = StrIndexNC(DaString,old,i,@FwdScan)

If i == 0
Break
EndIf

count = count + 1
i = i + oldlen 
EndWhile

bbsize = bbsize+(count*(newlen-oldlen))
EndIf

bb = BinaryAlloc(bbsize)

BinaryPokeStr(bb, 0, DaString)
BinaryReplace(bb, Old, new, @FALSE)

ans = BinaryPeekStr(bb,0,BinaryEODGet(bb))

BinaryFree(bb)

Drop(i, count, oldlen, newlen, bbsize, len)
return (ans)

#EndFunction
Return

Answer:

Tricky. I suspect a math error, but am unsure. Maybe add DebugTrace(@ON,"C:\trace.txt") to the top of the file AND as the first line of every UDS/UDF so as to capture the error. The return the entire debug trace log. I would like to see the values of all the variables when the problem occurs.

User Reply:

End of the Trace File where the error occurs.
--- Leaving UDF (strreplacenc) ---

len        = strlen(DaString) 
(4078) VALUE INT => 0

oldlen     = strlen(old) 
(4078) VALUE INT => 14

newlen     = strlen(new) 
(4078) VALUE INT => 10

bbsize     = len 
(4078) VALUE INT => 0

If newlen>oldlen 
(4078) END OPERATOR

bb         = BinaryAlloc(bbsize) 
(4078) VALUE BINBUF => 987659

BinaryPokeStr(bb, 0, DaString) 
(4078) VALUE INT => 0

BinaryReplace(bb, Old, new, @FALSE) 
(6235) VALUE INT => 0

TERMINAL WIL ERROR=>1588 (Unable to allocate or lock memory)

Answer:

The error occurs because the binary buffer 'bb' is of 0 length when passed to BinaryReplace.

As a workaround, make sure that the binary buffer passed to BinaryReplace, bb in your case, has a size of at least one. Maybe

if bbsize < 1 then bbsize = 1

Article ID:   W17406
File Created: 2009:08:11:08:35:02
Last Updated: 2009:08:11:08:35:02