Okay... so I'm trying to lock the memory I'm accessing rather than the
memory I want to store to. That's interesting that you don't have to do
it in both spots in the off chance the MemMgr wants to store in the same
place
as you do at the same time....
Anyways... it's now working, thanks gents..!
Nole Mailey
Ted Beisler
<[EMAIL PROTECTED]> To: "Palm Developer Forum"
<[EMAIL PROTECTED]>
Sent by: cc: (bcc: Nole
Mailey/pmc)
[EMAIL PROTECTED] Subject: Re: Chunk under-locked
(newbie ques)
palmos.com
08/05/2003 10:06 AM
Please respond to "Palm Developer
Forum"
You've pretty much got it. If you follow your code path however, you are
unlocking myRecord twice. Each time you unlock a record it decrements the
lock count. Since you are doing it twice, you are decrementing the count
to a number below zero, thus getting the "Chunk under-locked" error. If
DmGetRecord fails, it shouldn't have locked anything, so get rid of the
second MemHandleUnlock. You should be doing a DmReleaseRecord when you're
done too.
At 09:50 05/08/2003 -0500, you wrote:
>Hi all....
>
>This is a bit of a fundamental question here but I think I only barely
>grasp how this whole Locking and Unlocking chunks is all about, not
>to mention I'm a newbie programmer. :\
>
>I realize you need to set aside a block or "chunk" of memory before
>assigning a variable any value but it's the how in some scenarios that
>is messing me up... anyways... I hope this isn't too much of a C question
>as it is a Palm Dev Forum question.....
>
>My function calls to the database for a particular record. The problem is
>I'm trying to unpack it to my struct (onOrder) but I'm getting a "Chunk
>under-locked" error.
>
>So, how do I lock the chunk while passing it through the function....?!?!
>My function definition below...
>
> static Err GetOrderRecord(DmOpenRef *dmReftoSync, UInt16 recordNum,
>OnOrder *onOrder)
>{
> Err err = 0;
> MemHandle myRecord = DmGetRecord(dmReftoSync, recordNum);
>
> if(!myRecord)
> err = DmGetLastErr();
> else
> {
> UnpackOnOrder(onOrder, (PackedOnOrder *)
>MemHandleLock(myRecord));
> MemHandleUnlock(myRecord);
> }
> MemHandleUnlock(myRecord);
> return err;
>}
>
>
>Nole Mailey
>Data Conversion Specialist
>ProfitMaster Canada
>1.800.340.4492
>www.pmcanada.com
>[EMAIL PROTECTED]
>
>
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe,
>please see http://www.palmos.com/dev/support/forums/
Ted Beisler
SPRUCE Computer Systems, Inc.
[EMAIL PROTECTED]
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
> -----Original Message-----
> From: [EMAIL PROTECTED]
> Sent: Tuesday, August 05, 2003 7:50 AM
>
> Hi all....
>
> I realize you need to set aside a block or "chunk" of memory
> before assigning a variable any value but it's the how in
> some scenarios that is messing me up... anyways... I hope
> this isn't too much of a C question as it is a Palm Dev Forum
> question.....
The Palm OS memory manager moves memory around to reduce fragmentation.
So the idea is, when you need to write a piece of memory, you
temporarily have to lock it down first, and get its address (e.g., a
pointer to it). While locked, the OS does not move the memory around so
that its address does not change.
Once you're done with your read/write operation, you unlock the chunk
and the address (pointer) immediately becomes invalid. This may seem
like a hassle at first, and inefficient, but it's really a Good Thing.
> static Err GetOrderRecord(DmOpenRef *dmReftoSync, UInt16
> recordNum, OnOrder *onOrder) {
> Err err = 0;
> MemHandle myRecord = DmGetRecord(dmReftoSync, recordNum);
If you're just reading the record and not writing to it, use
DmQueryRecord(), and not DmGetRecord(). It's more efficient. Ok so
myRecord is a handle to a movable chunk...
> if(!myRecord)
> err = DmGetLastErr();
> else
> {
> UnpackOnOrder(onOrder, (PackedOnOrder *)
> MemHandleLock(myRecord));
You've locked down the chunk so that UnpackOnOrder() can safely work on
it w/o having the address change. In other words, myRecord now is a
handle to a non-movable chunk.
> MemHandleUnlock(myRecord);
> }
You've unlocked the chunk now, so you're back to your initial state of
having myRecord being a movable chunk.
> MemHandleUnlock(myRecord);
You've just un-locked the chunk for a second time, which is not
necessary because it's already unlocked. You will get an under-locked
chunk error. Always match your MemHandleLock()s with your
MemHandleUnlocks() one-to-one, and you'll be fine.
Also, any record acquired with DmGetRecord() must be released with
DmReleaseRecord() when you are done with it, as the documentation
states; however, DmQueryRecord does not have this requirement.
DmGetRecord() is for reading/writing a record, whereas DmQueryRecord()
is just for a quick read.
-Jeff Ishaq
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/