Palm Mem Management

yakconspiracySoftware and s/w Development

Dec 14, 2013 (3 years and 8 months ago)

100 views

Palm memory management



http://www.codeproject.com/ce/palm_memorymanagment.asp




Although newer Palms are getting more and more RAM most still have under 16MB
and none of them have ha
rd drives. All applications and databases are stored in the
RAM so Palms have to do things a little differently than PCs. We wouldn't want our
applications overwriting permanent storage now would we.

The RAM is divided into two sections: the storage area
and the dynamic area (or
dynamic heap). As you can guess, the storage area is where permanent data resides,
like applications and databases, and is handled by the
Database Manager
. The
dynamic heap is used for Palm OS globals, Palm OS dynamic allocations, your
application's global variables, your application's stack space, and any dynamic
allocations your application makes. The dynamic heap is handled by t
he
Memory
Manager

and its size depends on the amount of RAM your Palm has, the OS version
and the applications you have installed.

Because of the limited amount
of dynamic memory, the Palm OS needs to be able to
move chunks of memory around to keep its free space contiguous so there is enough
room for new allocation. Thus there are two types of memory chunks,
pointers

and
handles
. Pointers are nonmovable chunks of

memory, whereas handles are movable
by the Palm OS. It is recommended that you use handles as much as possible.

The Memory Manager API

In order to manipulate memory on the Palm, you must use the
Memory Manager
API
.



Palm memory
http://www.palmos.com/dev/support/docs/palmos/Memory.html#1025850



The Palm OS system software i
s designed around a 32
-
bit architecture. The system uses 32
-
bit addresses, and its basic data types
are 8, 16, and 32 bits long.

The Palm OS divides the total available RAM store into two logical areas:
dynamic RAM

and
storage RAM
. Dynamic RAM is used
as
working space for temporary allocations, and is analogous to the RAM installed in a typical desktop system. The remainder of
the available RAM on the card is designated as storage RAM and is analogous to disk storage on a typical desktop system.

Because p
ower is always applied to the memory system, both areas of RAM preserve their contents when the handheld is turned
"off" (i.e ., is in low
-
power sleep mode). See
"Palm OS Power Modes"

in the chapter
"Palm System Support"

in this book. All of
storage memory is preserved even when the handheld is reset explicitly. As part
of the boot sequence, the system software
reinitializes the dynamic area, and leaves the storage area intact.

The entire dynamic area of RAM is used to implement a single heap that provides memory for dynamic allocations. From this
dynamic heap
, the syste
m provides memory for dynamic data such as global variables, system dynamic allocations (TCP/IP,
IrDA, and so on, as applicable), application stacks, temporary memory allocations, and application dynamic allocations (such
as
those performed when the applic
ation calls the
MemHandleNew

function).

The entire amount of RAM reserved for the dynamic heap is always dedicated to this use, regardless of whether it is actual
ly used
for allocations. The size of the dynamic area of RAM on a particular handheld varies according to the OS version running, the

amount of physical RAM available, and the requirements of pre
-
installed software such as the TCP/IP stack or IrDA stack.
Table 5.1

provides more information about the dynamic heap space that currently available combinations of OS and hardware provide.

Traditional file system uses a buffer
to store information before it can be read/write into
memory.


Palm does not have a

buffer and only needs to be able to store information into memory.


In order to store data, it first splits up the data into records which it then stores these
records into

a database system that has been setup scattered through out memory.


Traditional file systems will store data in a contiguous chunk.


Databases contain related data. Databases can be spread out over multiple Ram
structures.


To find data it goes to the D
ata Manager searches for it in an index which will tell where
the database is located in memory then goes directly to the memory and retrieves the
data.


Each record entry stored in a record list has three fields and is 8 bytes in length.
Each entry has th
e local ID of the record which takes up 4 bytes: 1 byte of attributes and
a 3
-
byte unique ID for the record. The
attribute

field, shown in
Figu
re 6.1
, is 8 bits
long and contains 4 flags and a 4
-
bit category number. The category number is used to
place records into user
-
defined categories like "business" or "personal."

Each record has the following attributes.



The
delete

bit is set in the
attributes

flags, but its entry in the database
header remains until the next synchronization with the PC.



The
dirty

bit is set whenever a record is updated.



The
busy

bit is set when an application currently has a re
cord locked for
reading or writing.



The
secret

bit is set for records that should not be displayed before the user
password has been entered on the handheld.



Records can be resized.


When you ‘delete’ a record the local ID stored in the record entry
is set to 0 and is still on
the palm docking with a computer is required to delete the record or data from the palm.


Data manager can

Dm
CreateDatabase

DmDeleteDatabase
.
,

DmFindDatabase
,

DmGetDatabase
,

DmDatabaseInfo
,

DmSetDatabaseInfo
,

DmDatabaseSize
,

DmGetRecord


sets busy bit to confirm its being used ,

DmQueryRecord


lets you look at the record but not change it, doesn’t set the busy bit.,
DmReleaseRecord

resizerecord

newrecord

removerecord

archiverecord

deleterecord


The Resource Manager
^TOP^


Applications can use the Resource Manager much like the Data Manager to retrieve and
save chunks of data conveni
ently. The Resource Manager has the added capability of
tagging each chunk of data with a unique resource type and resource ID. These tagged
data chunks, called
resources
, are stored in resource databases. Resource databases are
almost identical in structu
re to normal databases except for a slight amount of increased
storage overhead per resource record (two extra bytes). In fact, the Resource Manager is
nothing more than a subset of routines in the Data Manager that are broken out here for
conceptual reaso
ns only.