*** WARNING *** Dangerously newbish questions follow.  

Chris Antos <[EMAIL PROTECTED]> wrote:

>>Programs should never request functionality without designing to make sure
>>that there is enough memory for success.  Or at least that is the followed
>
>but didn't we all agree that pre-flighting is bad and unreliable to begin
>with?

Forgive me Chris, what is "pre-flighting"?  Checking for resources before
using?

>so, there are two possibilities for Andrew's gremlins crash:
>1.  the dynamic heap gets crowded out by the storage heap and this is an OS
>problem.
>2.  the dynamic heap is reserved and cannot be crowded out, and therefore
>Andrew's app must be leaking dynamic memory and filling up the dynamic heap.

Oh, I'd definitely vote for the latter of the two. ;-)

I'm intuiting from Roger's suggestion in an earlier post that the dynamic
heap can't be crowded out by the storage heap (wild guess...not fact
based).  The intent is that the dynamic heap should always have room for
basic OS stuff, forms, battery warnings, alarms, menus
_no_matter_what_an_app_is_doing.  Please correct me if this assumption is
wrong.

As I said before, I'm going to post a seperate question on using the
console, but I'll ask this here since it seems relevant.  The primary cause
of memory leaks on the Palm must be allocating handles or pointers without
de-allocating them later, right?  After that, I'm stumped as to what else
might be a potential leak.  I've read threads about field resources
leaking, but I've only got a single field and I always free the memory used
by that field.

What's never been clear, (I can hear the seasoned pros sighing already), is
when one must explicitly allocate memory and when an implicit allocation is
fine.  For example:

char sString[ MAX_STRING_LENGTH ];

vs.

VoidHand hString = MemHandleNew( MAX_STRING_LENGTH );
pString = MemHandleLock( hString );
...do something with the string
MemHandleUnlock( hString );
MemHandleFree;

Memory is obviously allocated in either case.  But which is the preferred
method?  I see both methods in the example code.  Why would I choose one
method over the other?  The latter example uses 4 lines of code, not
including checking that the handle was allocated or declaring the pointer
while the former uses 1 line.  And I'm assuming here that neither of these
examples would leak, right?

Again, thanks for your patience.

Cheers,
--
Andrew Ball
[EMAIL PROTECTED]

Reply via email to