Home All Groups Group Topic Archive Search About
Author
21 Sep 2005 5:06 PM
Shailesh Patel
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

Author
21 Sep 2005 5:08 PM
Veign
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
--


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
>
>
Author
21 Sep 2005 5:30 PM
Shailesh Patel
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
>>
>>
>
>
Author
21 Sep 2005 7:27 PM
Ken Halter
"Shailesh Patel" <shail***@urnerbarry.com> wrote in message
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.
> ?

More error traps. You should basically have one trap per event.

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..
Author
21 Sep 2005 5:41 PM
Larry Serflaten
"Shailesh Patel" <shail***@urnerbarry.com> wrote

> 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 can keep an error handler active to trap it, but the error is that
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
Author
22 Sep 2005 8:18 AM
Jan Hyde
"Shailesh Patel" <shail***@urnerbarry.com>'s wild thoughts
were released on Wed, 21 Sep 2005 13:06:54 -0400 bearing the
following fruit:

>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.
>

Maybe the user is doing something you've never done.

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/]
Author
22 Sep 2005 4:08 PM
Someone
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
>
Author
23 Sep 2005 8:50 AM
Tony Proctor
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
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
> >
>
>
Author
24 Sep 2005 8:02 PM
Someone
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
>> >
>>
>>
>
>
Author
26 Sep 2005 9:56 AM
Tony Proctor
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
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.
>
>
> "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
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
> >> >
> >>
> >>
> >
> >
>
>
>