E
E
evgenyt20002020-05-07 17:28:22
C++ / C#
evgenyt2000, 2020-05-07 17:28:22

How to fix passing an array to a stream?

An array is passed to the stream (maybe I'm passing it incorrectly), after that I get strange numbers in the stream, although the operations there are not complicated
int *array = new int[mSize];

HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)a,&array,0,&tid);

int a(int *array)
{
    min = array[0]; max = array[0];
    for (i = 0; i < mSize; i++) { sum += array[i]; Sleep(12); }
    cout << "Sum   :" << sum << endl;
    for (i = 0; i < mSize; i++){if (min > array[i])  min = array[i];}
    cout << "Min   :" << min << endl;
    return 0;
}

5eb422b94d9e2470759333.png
perhaps it is necessary to transfer the size of the array, but it is not clear how to do this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-05-07
@evgenyt2000

int *array = new int[mSize];
...
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)a,&array,0,&tid);
...
int a(int *array)

In the call to CreateThread, it must be replaced &arraywith array, because the variable arrayis not an array, but a pointer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question