> AA>   MemPtrNew and MemHandleNew.
> AA>   check out part II of the PalmOS programming guide.. the manual provides
> AA>   everything you need :)
> 
> Ah... I don't think so... Example:
> 
> *) What will happen if you pass 0 for the size (*
> 
> is it "defined but undocumented" ? or is it "undefined" ?
> is it "OS version dependent" ? or not?
> if it'll not crush, what will it pass back? NULL? or some variable.
> 
> malloc - type function always have this problem, but none of the
> document for PalmOS gives me the answer.
> 
> # Same type of problem occurs for "Resize".
> # what if I passed NULL? what if I passed size 0? what if both?

  here is an excerpt taken from the SDK docs (3.0)

  ---
    part 1: Interface Management

    Chapter: Developing Palm OS Applications
    - Overview of Application Development
      . Avoid allocating zero-length objects    (page 38)

    It's not valid to allocate a zero-byte buffer, or to resize a 
    buffer to zero bytes. Palm OS 2.0 and previous releases allowed
    this practice, but future revisions of the OS may not permit
    zero length objects.
  ---

  it is clearly documented - you just have not found it yet. of course,
  any *decent* programmer would check that the size of the buffer is
  not zero? and perform any relevant error checking - as documented
  as well:

  ---
    part 1: Interface Management

    Chapter: Developing Palm OS Applications
    - Overview of Application Development
      . Check Results Codes When Allocating Memory (page 38)
  
    Because future devices may have larger or smaller amounts of 
    available memory, it is always a good idea to check results codes
    carefully when allocating memory. It's also good practice to  
    use the storage heap (and possibly file streams) to work with
    large objects.
  ---

  lastly, the C compilers interpret "0" as NULL - so i guess that
  should answer your question there.

  your code for memory allocation should look as follows:

  {
    BytePtr p;
    Word    size;

    size = ...;

    if (size != 0) {
      p = (BytePtr)MemPtrNew(size * sizeof(Byte));
      ErrFatalDisplayIf((p == NULL), "Oops, no memory available");
    }
    else {
      ErrFatalDisplayIf(true, "The buffer must be > 0 bytes in size");
    }
  }

> I've been looking for answer for these questions, but still have not
> found the answer.

  the answers are there.. you just need to LOOK for them :) the only
  problem that i see is that this "documentation" was really stored 
  in the wrong place in the SDK docs. it should be with the Memory 
  Management descriptions - not in the Interface Management chapters.
  
  that is not something you can bitch about to us developers on this
  list tho - maybe Palm will rewrite the SDK API's one day - for now,
  download the .pdf files that allow searching.

  cheers.

az.
--
Aaron Ardiri 
Java Certified Programmer      http://www.hig.se/~ardiri/
University-College i G�vle     mailto:[EMAIL PROTECTED]
SE 801 76 G�vle SWEDEN       
Tel: +46 26 64 87 38           Fax: +46 26 64 87 88
Mob: +46 70 656 1143           A/H: +46 26 10 16 11

Reply via email to