No, there's no way. And if there were, you shouldn't use it.

Recall that a handle is a reference to a pointer in a "master pointer table".
When you lock a handle and get a pointer back, you are getting the pointer from
the master pointer table.

Now think about what happens when you "free a handle". The corresponding block
of memory in the heap is marked as free, and something appropriate is done with
the entry in the master pointer table (in current OSes, the entry is set to
NULL, in 3.5, it will be part of a chain of free master pointer table entries).

Possibly, you could determine if the handle you're holding onto is valid based
on that information. But it would be a bad idea. What if something had come
along and called MemHandleNew?  If that MemHandleNew re-used the master pointer
table entry previously used by your (now stale) handle, your handle would
suddenly start referring to this new block. Your test for "freeness" would
suddenly indicate that the handle was now valid again!

Overall, the best thing to do is keep better track of whether or not you've
called MemHandleFree on a particular handle. I'm guessing that you have multiple
copies of a handle, and that part of your program is calling MemHandleFree on
one copy, and another part of your program is failing because its copy is no
longer valid. You may instead want to control access to the handle via a set of
routines:

MemHandle gHandle;
void MyCreateHandle(void)
{
     gHandle = MemHandleNew (...);
}

MemHandle MyDestroyHandle(void)
{
     MemHandleFree(gHandle);
     gHandle = NULL;
}

MemHandle MyGetHandle(void)
{
     return gHandle;
}

Use MyGetHandle to get *temporary* copies of the handle. Don't keep those
references around outside the scope of the function in which you called
MyGetHandle. That way, when one part of your program deletes the handle, the
other parts will reflect that change.

-- Keith







"Ken Glover" <[EMAIL PROTECTED]> on 11/24/99 11:56:14 AM

Please respond to [EMAIL PROTECTED]

Sent by:  "Ken Glover" <[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:    (Keith Rollin/HQ/3Com)
Subject:  How to check for a free handle?




Hello everyone.

Is there anyway to check if a handle is freed or not?
I get "free handle" error on emulator when performing
MemHandleUnlock(handle); when the handle is free.  I would like to check for
it before I perform the unlock.

By the way, can you free a handle that is locked?  If so, will the emulator
sill keep track of the lock count?  I seem to get "record left locked" error
on the emulator if I do this.  Would this be a problem?  It should not
matter because the handle is freed anyways.  I would like some thoughts on
this.

Thanks for reading this!!






Reply via email to