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