Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Saurabh Agarwal
Hi,

I am trying to lock/unlock a memory chunk.
But after some no of iterations, it gives error MemoryMgr.c, Line:3061,
Chunk over-locked.
Can anybody tell me where I have done mistake.
I have used MemHandleLock and MemHandleUnlock in pairs only i.e first
called MemHandleLock  and then MemHandleUnlock.
There is no change in order.
But when that piece of code is called around 8 to 9 times, it gives the
above error.

Is there any limitation on Locking/Unlocking a memory chunk?

Thanx.
Saurabh



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Aaron Ardiri
 I am trying to lock/unlock a memory chunk.
 But after some no of iterations, it gives error MemoryMgr.c, Line:3061,
 Chunk over-locked.
 Can anybody tell me where I have done mistake.
 I have used MemHandleLock and MemHandleUnlock in pairs only i.e first
 called MemHandleLock  and then MemHandleUnlock.
 There is no change in order.
 But when that piece of code is called around 8 to 9 times, it gives the
 above error.
 
 Is there any limitation on Locking/Unlocking a memory chunk?

you can only lock an item 16 times. at the 17th = crash.
lock/unlock increment and decrement the lock count. thats the
important thing.. so:

  MemHandleLock(memHandle);
  MemHandleLock(memHandle);
  MemHandleUnLock(memHandle);

will be fine until you call it 9 times :)

---
Aaron Ardiri
PalmOS Certified Developer
[EMAIL PROTECTED]
http://www.mobilewizardry.com/members/aaron_ardiri.php


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Saurabh Agarwal
sorry i could not understand ur reply.
u mean to say that MemHandleLock increases the count and then
MemHandleUnlock decreases the same count.
and so the net affect on this count remained zero. Is this waht u mean??

Or Lock and Unlcok increases a count by one. So I can lock-unlock that chunk
at max 16 times and 17th times, it will give error even if I have unlocked
it 16 times. If so then I might have to do major changes in my code?

saurabh



Aaron Ardiri [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  I am trying to lock/unlock a memory chunk.
  But after some no of iterations, it gives error MemoryMgr.c, Line:3061,
  Chunk over-locked.
  Can anybody tell me where I have done mistake.
  I have used MemHandleLock and MemHandleUnlock in pairs only i.e
first
  called MemHandleLock  and then MemHandleUnlock.
  There is no change in order.
  But when that piece of code is called around 8 to 9 times, it gives the
  above error.
 
  Is there any limitation on Locking/Unlocking a memory chunk?

 you can only lock an item 16 times. at the 17th = crash.
 lock/unlock increment and decrement the lock count. thats the
 important thing.. so:

   MemHandleLock(memHandle);
   MemHandleLock(memHandle);
   MemHandleUnLock(memHandle);

 will be fine until you call it 9 times :)

 ---
 Aaron Ardiri
 PalmOS Certified Developer
 [EMAIL PROTECTED]
 http://www.mobilewizardry.com/members/aaron_ardiri.php





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Aaron Ardiri
 sorry i could not understand ur reply.
 u mean to say that MemHandleLock increases the count and then
 MemHandleUnlock decreases the same count.
 and so the net affect on this count remained zero. Is this waht u mean??

if the lock count is greater than 16, it'll barf. end of story.

so, you should lock and unlock evenly. lock = +1, unlock = -1
if it dies after 16 locks, if means you have not unlocked at all
= bad.

---
Aaron Ardiri
PalmOS Certified Developer
[EMAIL PROTECTED]
http://www.mobilewizardry.com/members/aaron_ardiri.php


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Chris Tutty
From: Saurabh Agarwal [EMAIL PROTECTED]
 sorry i could not understand ur reply.
 u mean to say that MemHandleLock increases the count and then
 MemHandleUnlock decreases the same count.
 and so the net affect on this count remained zero. Is this waht u mean??
 
Yes, if your code is correct.  What everyone's implying is that 
these problems occur when you don't lock and unlock in pairs
so your code must have a bug somewhere.

Generally you're looking for a place where perhaps you lock
at the start of a function and unlock at the end but have a return 
in the middle of the function.  Another common problem is 
unlocks in complex if statements where one branch doesn't
include the unlock.

There are also Palm OS functions that will cause locking and
for which you have to do the correct thing to cause an unlock.

Chris Tutty


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Limits on Locking and Unlocking a memory chunk?

2004-08-05 Thread Alan Ingleby
Aaron Ardiri [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  sorry i could not understand ur reply.
  u mean to say that MemHandleLock increases the count and then
  MemHandleUnlock decreases the same count.
  and so the net affect on this count remained zero. Is this waht u mean??

 if the lock count is greater than 16, it'll barf. end of story.

 so, you should lock and unlock evenly. lock = +1, unlock = -1
 if it dies after 16 locks, if means you have not unlocked at all
 = bad.

Check your code paths.  What you're seeing is a definite result of
mismatched locks and unlocks.

You're locking the handle more times than you're unlocking it.

for (int i = 0; i  1000; i++)
{
MemHandleLock(mh);
MemHandleUnlock(mh);
}
Works fine.  That's 1000 locks.

Check all possible code paths.  You're missing something really obvious.

Alan



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/