C++ to .NET Csharp swig DoubleVector.ToArray()

82 Views Asked by At

I have an object named result, which contains a IntegerVector and a DoubleVector in C++. I generate with a Task(Of Results) n diferent results and have them in gotresults as Taks from result, that is in C++.

When I use gotresults(j).IntegerVector.ToArray() I have no problems, but using the gotresults(j).DoubleVector.ToArray() I get an index error.

When im debbuging I see the DoubleVector has information using gotresults(j).DoubleVector.count, but after the error shows it says the count is 0 and in Results View "Enumeration yielded no results".

¿Could anyone help me to get the DoubleVector from C++ correctly to an object in VB.NET?

Simple code below (I have TASKS = 1 now, but it still doesnt work):

  1. In C++:

     struct ResultCPP {
    
         std::vector<double> doubleseriecpp
         std::vector<int> intseriecpp
    
     }
    
     Necesaries to calculate a doubel series and int series to get the ResultCPP object in C++.
    
  2. functionAsync(param) and ResultContainer:

     Friend Class ResultContainer
    
          Public doubleserie As Swig4CSharp.DoubleVector
          Public integerserie As Swig4CSharp.IntVector
    
     End Class
    
     Private Async Function funcionAsync(params) As Task(Of ResultContainer)
    
         Return Await Task.Run(Function()
    
             Dim result as New ResultContainer
    
             Dim resultaux As New CCode.ResultCPP
    
             resultaux = CodeCPP.calculate(params)
    
             result.doubleserie = resultaux.doubleseriecpp
             result.intserie = resultaux.interiecpp
    
             Return result
    
         End Function)
    
     End Function    
    
  3. VB.NET.

     Const TASKS As Integer = 1
    
     For i As Integer = 0 to n Step TASKS
    
         Dim correlation task As New List(Of Task(Of ResultContainer))
    
         For j As Integer = 0 to TASKS -1
             function_task.Add(functionAsync(param))
         Next
    
         Task.WaitAll(correlation_task.ToArray)
    
         For j As Integer = 0 To TASKS - 1
    
         Dim corrdates() As Integer
         Dim corrseries() As Double
    
         If correlation_task(j).Result.corr_serie Is Nothing or 
             correlation_task(j).Result.corr_date Is Nothing Then
    
             ReDim corrdates(0)
             corrdates(0) = Integer.MinValue
    
             ReDim corrseries(0)
             corrseries(0) = Double.MinValue
    
         Else
    
            corrdates_temp1 = 
            correlation_task(j).Result.intseries.ToArray()
            Threading.Thread.Sleep(1000)
    
            corrseries_temp = 
            correlation_task(j).Result.doubleseries.ToArray()
            Threading.Thread.Sleep(1000)
    
         End If
    
     Next
    

    Next

And with few series (a small n) I get no problem, but if the n is bigger, then I get a problem in doubleseries.ToArray() and if I debbug I see it starts to generate te array in VB.NET, but then at some point failes to keep building it. Its usually with doubleseries, not so usual with intseries.

Thank you very much for the help!!!

0

There are 0 best solutions below