[EMAIL PROTECTED] wrote:

So is using the NULL type of delimiting faster or using

Char var1 = "test";
Char var2 = 25";

typedef struct
{
 Char name[64];
 Char level[64];
} QuestType;

QuestType Appt:

StrCopy (Appt.name, var1);
StrCopy ( Appt.level, var1);

blah, blah, blah.........

this would make reading back the record easier, but seems it would
have limitations and some wasted memory space. But you would allways
know the offset IE names data 0-63 levels data 64-127
If you are going to have a lot of records, then it is probably best to reduce the record size by using null terminated strings. Hard to say if you will suffer a speed penalty, without really knowing what the database will look like, and what king of access (how often) you need to find a record in the db. Remember that you might save some computation time by using fixed record field lengths, but you might also LOSE time when you need to read/write/clear those larger blocks of memory for each record.

Often, people will put a length variable preceding the string of characters, so that you can quickly access the start of the next string. So, your record structure might look something like this concept:

UInt16     str1len
char[#]     str1
char         null
UInt16     str2len
char[#]     str2
char         null

When you lock the record handle to access the data, you could immediately read the str1len value, and use that as an offset to jump right to the start of the next string, or its corresponding length variable.

Bob




Robert Moynihan <[EMAIL PROTECTED]> wrote ..
[EMAIL PROTECTED] wrote:

Logan Shaw <[EMAIL PROTECTED]> wrote ..


druid wrote:
Yea, but that brings up another question
If the structure of a record is actualy a series on
teminated strings, when you retrieve records, how do you
know the length of any field in that record
You just have to figure out a way to do this yourself.
You mean that a record is not normally just a single string
with delimiters


That's right. A record is a chunk of memory, and you can format it any way that you like. You CAN choose to delimit it with NULL characters, as you have done below by specifically including the trailing NULLs in the DmWrite commands.

Like this
size = StrLen(name)+1+ StrLen(level)+1;
 index = dmMaxRecordIndex;
 h = DmNewRecord(dbPtr, &index, size);
 ptr = MemHandleLock(h);
 Offset = 0;
 DmWrite(ptr, Offset, (const void *)name, StrLen(name)+1);
 Offset += StrLen(name)+1;
 DmWrite(ptr, Offset, (const void *)level, StrLen(level)+1);
 err = DmCloseDatabase(dbPtr);

maybe im doing this all wrong


This stuff seems to look OK, as long as you have previously defined all those variable types correctly. How do you know the length of any field? Using the method above, the only real way is to iterate through the record, looking at each string in turn.

Bob

--
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please
see http://www.palmos.com/dev/support/forums/


--
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to