Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming of Mobile and Handheld Devices Lecture 9: Memory, databases and files on Palm OS Rob Pooley

Similar presentations


Presentation on theme: "Programming of Mobile and Handheld Devices Lecture 9: Memory, databases and files on Palm OS Rob Pooley"— Presentation transcript:

1 Programming of Mobile and Handheld Devices Lecture 9: Memory, databases and files on Palm OS Rob Pooley rjp@macs.hw.ac.uk

2 Application memory management In Palm OS the Memory Manager APIs exist mainly for use by the Data Manager to manage storage heaps. Application developers should use the standard C library functions such as malloc() and free() to manage dynamic memory.

3 Pointers and handles When an application requests an immovable chunk it receives a pointer to that chunk. The pointer is simply that chunk’s address in memory. –Because the chunk cannot move, its pointer remains valid for the chunk’s lifetime; thus, the pointer can be passed “as is” to the caller that requested the allocation. –When an application requests a movable chunk, the operating system generates a pointer to that chunk, just as it did for the immovable chunk, but it does not return the pointer to the caller. Instead, it –stores the pointer to the chunk, called the master chunk pointer, in a master pointer table that is used to track all of the movable chunks in the heap, and –returns a reference to the master chunk pointer. This reference to the master chunk pointer is known as a handle. –It is this handle that the operating system returns to the caller that requested the allocation of a movable chunk.

4 Allocating and Freeing Memory Chunks To allocate a movable chunk, call MemHandleNew() and pass the desired chunk size. To free a memory chunk given its handle, call MemHandleFree(). The Memory Manager provides similar functions that work with immovable chunks: –MemPtrNew() allocates a memory chunk and returns a pointer to it, while –MemPtrFree() frees a chunk given its pointer.

5 Locking movable memory chunks Before you can read or write data to a movable chunk you must call MemHandleLock() to lock it and get a pointer to it. Then, when you no longer need direct access to the chunk’s contents, call MemHandleUnlock(). (Note that after a call to MemHandleUnlock, the pointer your application was using to access the chunk’s contents is no longer valid.)

6 Manipulating Chunk Contents The Memory Manager provides three utility functions that you can use when working with the contents of a chunk: –MemMove() moves memory from one place to another. –MemSet() fills memory with a specific value. –MemCmp() compares two regions of memory.

7 Databases Palm OS doesn’t make use of a traditional file system. Instead of files, Palm OS applications work with databases. Databases organize related rows (for schema databases) or records (for non-schema databases); each belongs to one and only one database. A database may be a collection of all address book entries, all datebook entries, and so on. A Palm OS application can create, delete, open, and close databases as necessary, just as a traditional file system can create, delete, open, and close a traditional file

8 Types of database in Palm OS Schema databases, which were introduced in Palm OS Cobalt, bear a strong resemblance to relational databases. Data is organized into tables, which consist of rows and columns. Schema databases use the concept of a schema to define the structure of a table row. Unlike relational databases, however, schema databases don’t allow you to perform joins and other complex operations.

9 Types of database in Palm OS - 2 Classic databases are supported for compatibility with earlier versions of Palm OS. All versions of Palm OS back to Palm OS 1.0 support this database format, this is the format used by applications running on Palm OS Cobalt through PACE.

10 Types of database in Palm OS - 3 Extended databases are an “extended” version of classic databases. There are three primary differences between classic and extended databases: 1.extended databases records can exceed 64K in length (classic records cannot); 2.Extended databases are uniquely identified by a combination of name and creator ID (classic databases are uniquely identified by name alone); 3.extended databases can store data using the processor’s native endianness –(classic databases must store record data using big- endianness, for compatibility with the 68K-based Dragonball CPU used in the early Palm OS devices)

11 Summary of Palm OS section Palm OS is widely used and works well on Palm devices Palm OS has some good tools Palm OS Developer Kit is not really “finished” There is a lack of really good, simple to understand documentation on Palm OS programming It seems likely that J2ME will displace Palm OS as the most widely used application development for Palm devices J2ME also runs on phones etc.

12 References The full documentation for Palm tools is available online at: –www.palmos.com/dev/support/docs/www.palmos.com/dev/support/docs/ A good tutorial can be found in Palm OS Programming 2nd Edition, Rhodes and McKeehan, O’Reilly Books O’Reilly example is available online at: –www.oreillynet.comwww.oreillynet.com


Download ppt "Programming of Mobile and Handheld Devices Lecture 9: Memory, databases and files on Palm OS Rob Pooley"

Similar presentations


Ads by Google