--On 14 July 2001 18:11 -0700 Jim Schram <[EMAIL PROTECTED]> wrote:

> At 11:12 PM +0100 2001/07/14, Igor Mozolevsky wrote:
>> --On 14 July 2001 14:46 -0700 Jim Schram <[EMAIL PROTECTED]> wrote:
>>
>>> Well, a little common sense on your part should have caused you to ask
>>> yourself how an API which takes a pointer into random memory could
>>> possibly deallocate that memory.
>>
>> Quite simply:-
>>
>># define FAILURE 1
>># define SUCCESS 0
>># define NIL 0
>>
>> UInt8 func1(void) {
>> MemPtr foo;
>>
>> ...
>> if((foo = MemPtrNew(...)) == NIL)
>> return FAILURE;
>>
>> ...
>> if(funct2(&foo) == FAILURE)
>> return FAILURE;
>> }
>>
>> UInt8 func2(MemPtr *ptr) {
>> ...
>> if(MemPtrFree(*ptr) == NIL)
>> return FAILURE;
>> }
>
> Note how MemMove specifies void * parameters, while func2 specifies
> MemPtr parameters. This tells you that func2 requires pointers to
> dynamically allocated memory blocks, while MemMove does not. Thus MemMove
> cannot possibly safely deallocate memory passed to it, while func2 may
> (and in the above implementation, does).

Maybe that was a bad example, here's a better one:-

# define FAILURE 1
# define SUCCESS 0
# define NIL 0

UInt8 func1(void) {
  UInt8 foo; // reserves memory for 1 byte
  ...
 if(func2(&foo) != SUCCESS) // frees the reserved memory, or at least tries 
to...
  return FAILURE;

 return SUCCESS;
}

UInt8 func2(void *ptr) {
 ...
 if(MemPtrFree(ptr) == NIL)
  return FAILURE;
}

IM ;-)

-- 
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