TheSwamp
Code Red => .NET => Topic started by: MaksimS 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:
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
-
you might have a look at this thread too
http://www.theswamp.org/index.php?topic=14495.msg186823#msg186823
-
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:
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
-
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?
-
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?
-
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.