Jak zaalokować taka zmienną Uint8Array ?
Z tego co widzę to moja metoda działa , ale czy to tak powinno być używane ?
Co to za dokładnie funkcja, czy jest udokumentowana, a może to jest funkcja napisana pod LabView i masz kod do niej (AFAIK LabView używa C z własnymi bibliotekami)?
Tu nie ma innego sposobu, trzeba zacząć od dokumentacji lub przeanalizować włąściwy kod.
Googlanie znalazłem coś takiego:
Your doing this pretty wrong!
hROI = (Uint8ArrayBase**) DSNewHandle (sizeof (Uint8ArrayBase));
(*hROI)->dimSizes[0] = 60;
(*hROI)->dimSizes[1] = 30;
(*hROI)->elt[0] = 0;
This only allocates a memory area that can hold the dimSizes header and a single data element. Don't try to write to (*hROI)->elt[1] ever or you are going to corrupt memory, and if you are lucky it will crash. If you have bad luck nothing seemingly bad will happen but you have destroyed memory contents belonging to something else in LabVIEW, by writing over the end of the allocated buffer.
Instead you need to do this:
int32 dimSizeArr[2];
dimSizeArr[0] = 60;
dimSizeArr[1] = 30;
Uint8Array array = AllocateUint8Array(dimSizeArr);
if (!array)
err = mFullErr;
else
{
// do whatever you need to do with the array
err = DeallocateUint8Array(&array);
}
However it is likely that your function actually creates this array! In that case you would not need to first create it. It really depends if your function somehow initializes this array or simple just references it.
If you happen to have two loops in there, with both autoindexing array output tunnels that get returned into this array parameter at the end you can actually do something like this:
Uint8Array array = NULL;
double retval = SlantedEdgeSFR4(frequency, y, x, &array);
if (array)
{
// do something with the data in the array
for (i = 0; i < (*array)->dimsSizes[0]; i++)
{
for (j = 0; j < (*array)->dimSizes[1]; j++)
{
(*array)->elm[(*array)->dimSizes[1] * i + j] == something;
}
}
err = DeallocateUint8Array(&array);
}
In case you have already a dizzy head from all the pointers, handles, array subscripts and more, now you know why you prefer to program in LabVIEW rather than in C! :)
And just to show you what the functions most likely look like internally:
Uint8Array AllocateUint8Array(int32 *dimSizeArr)
{
return (Uint8Array)DSNewHClr(sizeof(int32) * 2 + dimSizeArr[0] * dimSizeArr[1];
}
MgErr __cdecl ResizeUint8Array(Uint8Array *hdlPtr, int32 *dimSizeArr)
{
return = NumericArrayResize(uB, 2, (UHandle*)hdlPtr, dimSizeArr[0] * dimSizeArr[1];
}
MgErr __cdecl DeAllocateUint8Array(Uint8Array *hdlPtr)
{
if (hdlPtr)
{
MgErr err = noErr;
if (*hdlPtr)
{
err = DSDisposeHandle((UHandle)*hdlPtr);
*hdlPtr = NULL;
}
return err;
}
return mgArgErr;
}
ChatGPT nie jest nawet blisko odpowiedzi.