Hi!

> >I have a question about locking and releasing handles to memory. The
> >Palm OS Reference states I should release locked memory as soon as
> >possible, whereas some posts on this forum suggest locking/releasing
> >will take up valuable CPU cycles and not releasing as soon as possible
> >might not be that harmful after all.
>
> The reason to unlock handles is to allow the memory manager to shuffle things around 
>to make room. If you're doing something that requires speed, you probably want to 
>avoid allocating memory during the operation, which means there is no need to unlock 
>handles during the operation either. I'd suggest using a debugger to isolate the 10% 
>of the code that runs 90% of the time, and if lock/unlock or memory allocation is a 
>significant portion of that 90%, keep the handle locked for the entire duration of 
>the operation. Unless you've done profiling and found that it's a problem, I wouldn't 
>worry about it.

Oops, I asked the wrong question (I shouldn't write e-mails early in the morning). I 
really wanted to ask about locking and releasing database records in resource 
databases.
Like in this typical piece of code:

    MemHandle resH = DmGetResource( bitmapRsc, maskID );
    ErrNonFatalDisplayIf( !resH, "Missing mask" );
    BitmapType* resP = (BitmapPtr)MemHandleLock(resH);

    WinDrawBitmap (resP, 0,0);

    MemPtrUnlock(resP);
    DmReleaseResource( resH );

Will there be any adverse side-effects to keeping the Resource locked if I need it a 
lot of times? The DmGetResource method does eat up a considerable amount of CPU 
cycles, according to the profiler log.

Cheers,
Tilo



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

Reply via email to