[What Danny Said ;)]
"packed" vs unpacked means (to me anyway)
unpacked:
struct{
UInt16 id
char field1[MAXLEN1]
char field2[MAXLEN2]
}test
This struct can be read/written directly to db records, but wastes (quite a
bit of) storage memory. It is a little faster for read/write/search - but
very little, and if field length varies between records there can be lots of
slack space in the db
packed:
struct{
UInt16 id
char * field1
char* field2
}test
or
struct{
UInt16 id
char fields[1]
}packedtest
Are both "packed" represenatations. The first is how the record looks when
not stored (ie, you've read a raw packed record, and parsed out the uint and
two strings and assigned them to the char *s or copied them into dynamic
memory...) the second struct shows how the record is actually stored in the
db, ie, as a int and a (variable length) array of chars. Personally I don't
define a struct like packedtest, I just dmwrite directly into a record using
multiple dmwrite calls, and also just parse out from the memory returned
from a read. I suppose there could be a speed advantage to a single dmwrite
vs. multiple smaller dmwrites, but for a small number of fields its probably
close to a wash.
- John
-----Original Message-----
From: Dyk Corman [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 18, 2002 11:20 AM
To: Palm Developer Forum
Subject: Difference between packed and unpacked databases.
Hi
I read so much about packing a structure that has more than one
textfield before saving it in a database.
Can anybody try to explain me how much memory this saves?
If I had a structure
struct{
UInt16 id
char * field1
char* field2
}test
and the text strings in field 1 and two don't have the same length (for each
record)
isn't one database record saved like
Address x: id
Address y: field1
Address z: field2
whereas z = y + strLen(field1) ?
So, where is the big advantage to pack everything to
a new structure
struct{
UInt16 id
char fields[1]
}packedtest
Sorry that I haven't get it yet... can anyone help?
many thanks,
Dyk
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/