Author Topic: ResultBuffer.ToArray glitches  (Read 5156 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
ResultBuffer.ToArray glitches
« on: June 20, 2007, 04:38:28 AM »
AutoCAD 2007 / Autodesk Map 3D 2007

Under certain (rather obscure) circumstances ResultBuffer.ToArray fails, throwing an error. It seems that described glitch happens more often on slower CPUs. Error-free workaround: create generic List(Of TypeValue), then iterate through ResultBuffer using For...Each loop, filling the List collection. When finished iterating, fire List.ToArray to get ResultBuffer's array of TypeValues:

Code: [Select]
    Public Function GetTypedValues(ByVal resultBuffer As ResultBuffer) As TypedValue()
        Dim m_Result As New List(Of TypedValue)

        If resultBuffer IsNot Nothing Then
            For Each m_TypedValue As TypedValue In resultBuffer
                m_Result.Add(m_TypedValue)
            Next
        End If

        Return m_Result.ToArray
    End Function

Now, use either For...Each loop or ResultBuffers' Enumerator - performance stays the same (on VB.NET, not sure about C#).

Regards,
Maksim Sestic


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8753
  • AKA Daniel
Re: ResultBuffer.ToArray glitches
« Reply #1 on: June 20, 2007, 05:05:35 AM »

TonyT

  • Guest
Re: ResultBuffer.ToArray glitches
« Reply #2 on: June 20, 2007, 12:21:31 PM »
What error does it throw?

AutoCAD 2007 / Autodesk Map 3D 2007

Under certain (rather obscure) circumstances ResultBuffer.ToArray fails, throwing an error. It seems that described glitch happens more often on slower CPUs. Error-free workaround: create generic List(Of TypeValue), then iterate through ResultBuffer using For...Each loop, filling the List collection. When finished iterating, fire List.ToArray to get ResultBuffer's array of TypeValues:

Code: [Select]
    Public Function GetTypedValues(ByVal resultBuffer As ResultBuffer) As TypedValue()
        Dim m_Result As New List(Of TypedValue)

        If resultBuffer IsNot Nothing Then
            For Each m_TypedValue As TypedValue In resultBuffer
                m_Result.Add(m_TypedValue)
            Next
        End If

        Return m_Result.ToArray
    End Function

Now, use either For...Each loop or ResultBuffers' Enumerator - performance stays the same (on VB.NET, not sure about C#).

Regards,
Maksim Sestic



MaksimS

  • Guest
Re: ResultBuffer.ToArray glitches
« Reply #3 on: June 21, 2007, 05:07:01 AM »
Need to check this out in release history first, then I'll post it here.

The glitch appers more frequent on slower CPUs, when ResultBuffer.ToArray is called within Transactions getting started and commited many times over in a loop. Seems to me like an issue with managed wrapper.

Regards,
Maksim Sestic

What error does it throw?

TonyT

  • Guest
Re: ResultBuffer.ToArray glitches
« Reply #4 on: June 21, 2007, 05:36:04 PM »
Hard to believe that CPU speed has any bearing
on that.  What's also puzzling is that your workaround
is almost the same thing AsArray() does internally.

Need to check this out in release history first, then I'll post it here.

The glitch appers more frequent on slower CPUs, when ResultBuffer.ToArray is called within Transactions getting started and commited many times over in a loop. Seems to me like an issue with managed wrapper.

Regards,
Maksim Sestic

What error does it throw?

MaksimS

  • Guest
Re: ResultBuffer.ToArray glitches
« Reply #5 on: June 25, 2007, 04:02:50 AM »
Funny, while browsing down the release history I found few different error codes related to the very same piece of code (ResultBuffer.ToArray). I know that proposed workaround is what AsArray should do anyways. It seems that managed ResultBuffer.AsArray doesn't handle something well internally. I'm also aware that CPU speed doesn't have much to do with anything :-) but that's something all configurations prone to mentioned error had in common.

Hard to believe that CPU speed has any bearing
on that.  What's also puzzling is that your workaround
is almost the same thing AsArray() does internally.