My $0.02
I use MemPtrNew() when I'm allocating something with a short lifespan, and
MemHandleNew() for longer-lived allocations. The whole idea (as far as I can
tell) with handle based allocation is that the OS can move memory around to
free up memory if it becomes fragmented. Since your app doesn't have
pointers to memory, but rather handles (essentially ID numbers) that
represent the allocated chunks that aren't locked, the OS can move the
contents of the chunks as needed, and then update an internal table that
maps the handle IDs to the correct locations in memory. Locking a handle to
get a pointer gets you essentially to the same place as allocating the
memory and getting a pointer via MemPtrNew().
So, in a function or block of code that allocates some memory, uses it, and
then frees it, I use MemPtrNew()/Free() -- examples might be string
handling, for instance.
When allocating large buffers that are going to live for long periods of
time (TCP/IP, IR, Serial buffers, Field buffers, Database record buffers,
global data pointers, etc) I use MemHandleNew/Free and keep the handle
unlocked when not in use.
John Schettino
Palm OS Programming For Dummies: http://schettino.tripod.com
Cooltown by HP: http://cooltown.hp.com
-----Original Message-----
From: Richard Hartman [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 03, 2000 2:31 PM
To: Palm Developer Forum
Subject: MemHandleNew() vs. MemPtrNew()
I have always been using MemHandleNew() and lcoking
& freeing it in each routine that needs access to that memory.
I have the feeling that this may be overkill.
I would like to invite comments on when to use MemHandleNew()
and when to use MemPtrNew(). What are the benefits and penalties
of each.
--
-Richard M. Hartman
[EMAIL PROTECTED]
186,000 mi/sec: not just a good idea, it's the LAW!
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html