|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Out of stack spaceHi,
How can I trap out of stack space error and remove it. I removed on error resume next occurrance in code to get errore information. Thank you. Shailesh Fix the code causing the error. Can't offer advice on how without seeing
some code though. -- Show quoteHide quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp Veign's Blog http://www.veign.com/blog -- "Shailesh Patel" <shail***@urnerbarry.com> wrote in message news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... > Hi, > How can I trap out of stack space error and remove it. > I removed on error resume next occurrance in code to get errore information. > > Thank you. > > Shailesh > > That's what I am trying to find out. Program runs fine in vb6 environment.
But when I run exe on client computer, it throws out of stack space error. It does not throw this error on my development machine (running in vb environment) but if I run exe on my machine it crashes. ? Show quoteHide quote "Veign" <NOSPAMinveign@veign.com> wrote in message news:OB4Vm%23svFHA.3720@TK2MSFTNGP14.phx.gbl... > Fix the code causing the error. Can't offer advice on how without seeing > some code though. > > -- > Chris Hanscom - Microsoft MVP (VB) > Veign's Resource Center > http://www.veign.com/vrc_main.asp > Veign's Blog > http://www.veign.com/blog > -- > > > "Shailesh Patel" <shail***@urnerbarry.com> wrote in message > news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... >> Hi, >> How can I trap out of stack space error and remove it. >> I removed on error resume next occurrance in code to get errore > information. >> >> Thank you. >> >> Shailesh >> >> > > "Shailesh Patel" <shail***@urnerbarry.com> wrote in message More error traps. You should basically have one trap per event.news:uOyFKJtvFHA.2932@TK2MSFTNGP10.phx.gbl... > That's what I am trying to find out. Program runs fine in vb6 environment. > But when I run exe on client computer, it throws out of stack space error. > It does not throw this error on my development machine (running in vb > environment) but if I run exe on my machine it crashes. > ? Code that causes excessive recursion will eventually run out of stack space. For example, start a new project, drop a button on the form and run this. When you click the button, you'll get an Out of Stack Space error because the click event is firing, which causes the code to run, which causes the click event to fire, which.... (you get it) '====== Private Sub Command1_Click() Debug.Print "Clicked", Timer Command1.Value = True End Sub '====== You can prevent that recursion with a flag. This code's using a static flag to determine whether or not to run the "Click" code again. You'll see that it's only going to run once per click instead of the 100's like the code above. '====== Private Sub Command1_Click() Static bHereAlready As Boolean If Not bHereAlready Then bHereAlready = True Debug.Print "Clicked", Timer Command1.Value = True bHereAlready = False End If End Sub '====== -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups.. "Shailesh Patel" <shail***@urnerbarry.com> wrote You can keep an error handler active to trap it, but the error is that> How can I trap out of stack space error and remove it. > I removed on error resume next occurrance in code to get errore information. you've used up too much memory (basically). To recover you need to realease that memory. Which of the possible causes listed in VB Help fits your situation? LFS "Shailesh Patel" <shail***@urnerbarry.com>'s wild thoughts were released on Wed, 21 Sep 2005 13:06:54 -0400 bearing thefollowing fruit: >Hi, Maybe the user is doing something you've never done.>How can I trap out of stack space error and remove it. >I removed on error resume next occurrance in code to get errore information. > >Thank you. > Can the user recreate this easily? Jan Hyde (VB MVP) -- Successfully: To completely suck up vile fluids. (Keith Jackson) [Abolish the TV Licence - http://www.tvlicensing.biz/] Are you using large fixed arrays in any procedure? These take stack space,
unless they are defined outside any function and put in a standard module. Dynamic arrays on the other hands take only 4 bytes. If you are using a QuickSort routine, then the problem might be there. QuickSort routines usually call themselves. Also, see my post here in how to debug your app using VC: http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/f2a3271d08413cf9/aaf7fa99933b4b29 Show quoteHide quote "Shailesh Patel" <shail***@urnerbarry.com> wrote in message news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... > Hi, > How can I trap out of stack space error and remove it. > I removed on error resume next occurrance in code to get errore > information. > > Thank you. > > Shailesh > That's not true. Stack-based array objects have their SafeArray descriptor
on the stack (which is small), but the array body is allocated from the heap just like any other array. You can show this yourself, e.g. ' Returns address of the address of the associated SafeArray descriptor Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ Ptr() As Any) As Long Private aa(10) As Long Private Sub Form_Load() Dim v As Long, a(10) As Long Debug.Print Hex(VarPtr(v)) Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) End Sub Tony Proctor "Someone" <nob***@cox.net> wrote in message news:OFAYe.45723$ct5.29086@fed1read04...> Are you using large fixed arrays in any procedure? These take stack space, http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/f2a3271d08413cf9/aaf7fa99933b4b29> unless they are defined outside any function and put in a standard module. > Dynamic arrays on the other hands take only 4 bytes. > > If you are using a QuickSort routine, then the problem might be there. > QuickSort routines usually call themselves. > > Also, see my post here in how to debug your app using VC: > > Show quoteHide quote > > > "Shailesh Patel" <shail***@urnerbarry.com> wrote in message > news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... > > Hi, > > How can I trap out of stack space error and remove it. > > I removed on error resume next occurrance in code to get errore > > information. > > > > Thank you. > > > > Shailesh > > > > Thanks for correcting me. I did further testing and found out that VB6 used
28 bytes in the stack. 24 bytes for SAFEARRAY structure + 4 unknown bytes. Perhaps VB6 decided to implement the 2 arrays as a single array with 2 dimensions. Normally you would have 8 additional bytes per extra dimension, not 4, so I am not sure how VB6 is doing it internally. Here is the revised code: ' Returns address of the address of the associated SafeArray descriptor Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ Ptr() As Any) As Long Private aa(100) As Long Private Sub Form_Load() Dim v As Long, a(100) As Long, v2 As Long Debug.Print Hex(VarPtr(v)); " "; Hex(VarPtr(v2)) Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) End Sub This prints the following: 13F8AC 13F88C 13F828 1FD890 13F828 1FDA58 Notice how a() and aa() have the same pointer to the same SAFEARRAY structure. I even found this to be true if dimmed a() As String or Double, a different data type. I found this to be true even with an EXE version. It's best not focus on what the optimizer in VB does. VB's compiler does source level optimization so the result could vary from one source to another. I may have gotten confused with VB3 and prior, since MS started using SAFEARRAY for VB4 and above, as far as I can remember. By comparison, C++ uses the stack if it was inside a function, unless you use the "static" keyword. Show quoteHide quote "Tony Proctor" <tony_proctor@aimtechnology_NoMoreSPAM_.com> wrote in message news:Oo1FmvBwFHA.464@TK2MSFTNGP15.phx.gbl... > That's not true. Stack-based array objects have their SafeArray descriptor > on the stack (which is small), but the array body is allocated from the > heap > just like any other array. You can show this yourself, e.g. > > ' Returns address of the address of the associated SafeArray descriptor > Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ > Ptr() As Any) As Long > > Private aa(10) As Long > > Private Sub Form_Load() > Dim v As Long, a(10) As Long > > Debug.Print Hex(VarPtr(v)) > Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) > Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) > End Sub > > Tony Proctor > > "Someone" <nob***@cox.net> wrote in message > news:OFAYe.45723$ct5.29086@fed1read04... >> Are you using large fixed arrays in any procedure? These take stack >> space, >> unless they are defined outside any function and put in a standard >> module. >> Dynamic arrays on the other hands take only 4 bytes. >> >> If you are using a QuickSort routine, then the problem might be there. >> QuickSort routines usually call themselves. >> >> Also, see my post here in how to debug your app using VC: >> >> > http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/f2a3271d08413cf9/aaf7fa99933b4b29 >> >> >> "Shailesh Patel" <shail***@urnerbarry.com> wrote in message >> news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... >> > Hi, >> > How can I trap out of stack space error and remove it. >> > I removed on error resume next occurrance in code to get errore >> > information. >> > >> > Thank you. >> > >> > Shailesh >> > >> >> > > Sorry, that's my fault for creating such a simplistic example. VarPtrArray
actually returns the address of a compiler-generated temporary location that points to the real SafeArray descriptor. Hence, you're seeing the result of the compiler having used the same temporary location in 2 successive statements. That's not really a problem. I've expanded the code a little more to illustrate exactly what's inside the temporary location,. and what's in side the target SafeArray descriptors: Tony Proctor '----------- Form1 ---------------- Private Type SAFEARRAYBOUND cElements As Long lLbound As Long End Type Private Type SAFEARRAY cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long Bounds(0 To 5) As SAFEARRAYBOUND 'Reasonable limit End Type Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _ pDst As Any, pSrc As Any, ByVal ByteLen As Long) ' *(Src) -> *(Dst) ' Returns address of the address of the associated SafeArray descriptor Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ Ptr() As Any) As Long Private aa(10) As Long Private Sub Form_Load() Dim v As Long, a(10) As Long Debug.Print Hex(VarPtr(v)) Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) ShowA VarPtrArray(a) ShowA VarPtrArray(aa) End Sub Public Sub ShowA(ByVal lpAddr As Long) ' Diagnostics: Shows the contents of a SafeArray descriptor, passed by reference Dim desc As SAFEARRAY, iDim As Integer On Error GoTo ErrorHandler Debug.Print "ShowA (" & Hex(lpAddr) & ")" 'Address of descriptor pointer CopyMemory lpAddr, ByVal lpAddr, 4 Debug.Print "ShowA " & Hex(lpAddr) 'Descriptor pointer ' Read body of the SafeArray descriptor CopyMemory ByVal VarPtr(desc), ByVal lpAddr, Len(desc) With desc Debug.Print "cDims=" & .cDims Debug.Print "fFeatures=" & Hex(.fFeatures) Debug.Print "cbElements=" & .cbElements Debug.Print "cLocks=" & .cLocks Debug.Print "pvData=" & Hex(.pvData) For iDim = 0 To .cDims - 1 Debug.Print "bound" & iDim & "=" & _ .Bounds(0).lLbound & " To " & .Bounds(0).cElements + ..Bounds(0).lLbound - 1 Next iDim End With Exit Sub ErrorHandler: Debug.Print "ShowA exception: " & Err.Description End Sub '----------------------------------- "Someone" <nob***@cox.net> wrote in message news:khiZe.50299$ct5.43932@fed1read04...Show quoteHide quote > Thanks for correcting me. I did further testing and found out that VB6 http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/f2a3271d08413cf9/aaf7fa99933b4b29used > 28 bytes in the stack. 24 bytes for SAFEARRAY structure + 4 unknown bytes. > Perhaps VB6 decided to implement the 2 arrays as a single array with 2 > dimensions. Normally you would have 8 additional bytes per extra dimension, > not 4, so I am not sure how VB6 is doing it internally. Here is the revised > code: > > ' Returns address of the address of the associated SafeArray descriptor > Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ > Ptr() As Any) As Long > > Private aa(100) As Long > > Private Sub Form_Load() > Dim v As Long, a(100) As Long, v2 As Long > > Debug.Print Hex(VarPtr(v)); " "; Hex(VarPtr(v2)) > Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) > Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) > End Sub > > This prints the following: > > 13F8AC 13F88C > 13F828 1FD890 > 13F828 1FDA58 > > Notice how a() and aa() have the same pointer to the same SAFEARRAY > structure. I even found this to be true if dimmed a() As String or Double, a > different data type. I found this to be true even with an EXE version. It's > best not focus on what the optimizer in VB does. VB's compiler does source > level optimization so the result could vary from one source to another. > > I may have gotten confused with VB3 and prior, since MS started using > SAFEARRAY for VB4 and above, as far as I can remember. By comparison, C++ > uses the stack if it was inside a function, unless you use the "static" > keyword. > > > "Tony Proctor" <tony_proctor@aimtechnology_NoMoreSPAM_.com> wrote in message > news:Oo1FmvBwFHA.464@TK2MSFTNGP15.phx.gbl... > > That's not true. Stack-based array objects have their SafeArray descriptor > > on the stack (which is small), but the array body is allocated from the > > heap > > just like any other array. You can show this yourself, e.g. > > > > ' Returns address of the address of the associated SafeArray descriptor > > Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ > > Ptr() As Any) As Long > > > > Private aa(10) As Long > > > > Private Sub Form_Load() > > Dim v As Long, a(10) As Long > > > > Debug.Print Hex(VarPtr(v)) > > Debug.Print Hex(VarPtrArray(a)); " "; Hex(VarPtr(a(0))) > > Debug.Print Hex(VarPtrArray(aa)); " "; Hex(VarPtr(aa(0))) > > End Sub > > > > Tony Proctor > > > > "Someone" <nob***@cox.net> wrote in message > > news:OFAYe.45723$ct5.29086@fed1read04... > >> Are you using large fixed arrays in any procedure? These take stack > >> space, > >> unless they are defined outside any function and put in a standard > >> module. > >> Dynamic arrays on the other hands take only 4 bytes. > >> > >> If you are using a QuickSort routine, then the problem might be there. > >> QuickSort routines usually call themselves. > >> > >> Also, see my post here in how to debug your app using VC: > >> > >> > > Show quoteHide quote > >> > >> > >> "Shailesh Patel" <shail***@urnerbarry.com> wrote in message > >> news:eznns7svFHA.3864@TK2MSFTNGP12.phx.gbl... > >> > Hi, > >> > How can I trap out of stack space error and remove it. > >> > I removed on error resume next occurrance in code to get errore > >> > information. > >> > > >> > Thank you. > >> > > >> > Shailesh > >> > > >> > >> > > > > > > > |
|||||||||||||||||||||||