LabWindows/CVI

cancelar
Mostrando resultados para 
Pesquisar então 
Você quer dizer: 

SetHandleSize problems

I have been trying to use the NewHandle, SetHandleSize, DisposeHandle set of commands in the Programmer's Toolbox of LabWindows/CVI 7.0 and have been having problems. Has anyone else noticed this group of commands not working as advertised? I have re-implemented my function using calloc and free and it seems to work fine.
0 Kudos
Mensagem 1 de 5
3.520Exibições
I wrote a small test program and it seems to be working fine on my end. I'm wondering if you aren't adding the extra level of indirection that a handle introduces. That is, if you have a handle to a block of memory, you have to dereference that handle to get a pointer to the actual storage space and this address can (and probably will) change if you call SetHandleSize. However, the value of the handle itself won't change. This is to allow you to keep the handle around (possibly in a list or array) and have various portions of the program change and resize the memory; if you are using malloc and free, it can become burdonsome to update these addresses; handles solve this problem.

Here is the quick test app I wrote; note that after calling SetHandleSize, I have to set ptr again to "refresh" it with the possibly changed address (not doing this will undoubtedly cause problems):

int main(void)
{
Handle testHandle;
int i, *ptr;

if ((testHandle = NewHandle (10 * sizeof(int))) == 0)
{
printf ("error in NewHandle\n");
return 1;
}
ptr = *testHandle;
for (i = 0; i < 10; ++i)
ptr[i] = i + 1;
for (i = 0; i < 10; ++i)
printf ("%d\n", ptr[i]);
if (!SetHandleSize (testHandle, 25 * sizeof(int)))
{
printf ("error in SetHandleSize\n");
return 1;
}
for (i = 0; i < 10; ++i)
printf ("%d\n", ptr[i]);
ptr = *testHandle;
for (i = 0; i < 25; ++i)
ptr[i] = i + 1;
for (i = 0; i < 25; ++i)
printf ("%d\n", ptr[i]);
DisposeHandle (testHandle);
return 0;
}


Hope this helps!

-alex
0 Kudos
Mensagem 2 de 5
3.501Exibições
Yes, I am dereferencing the handle. I am using the command in other places in my code and it works fine. In this instance, I am using large blocks of data (2010 bytes each) and I don't know exactly how many blocks I will need. So each time I encounter a new requirement for a block I try to increase the block size by the same amount.
0 Kudos
Mensagem 3 de 5
3.493Exibições
In that case, could you elaborate on what kind of bad behavior you are seeing?

Regards,

-alex
0 Kudos
Mensagem 4 de 5
3.484Exibições
To satisfy my curiosity, I made a "stress test" type app (attached). It ran fine on my machine. If you can supply an example that doesn't work or give me some idea of what kinds of problems you were having, I'll look into this further.

Regards,

-alex
0 Kudos
Mensagem 5 de 5
3.479Exibições