Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PChar on disk

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I'm probably missing something easy on this one...but anyhow.

I have a file with what essentially amounts to several PChar values in a record. Now this value is fine in memory, but isn't working too well on disk (naturally since it's a pointer value). For disk the value is an array of characters.

The problem comes in two things:
1) I don't know the size of this field, which can be variable.
2) Fortunately it will always have #0 at the end, but will always terminate in the file with #0. Which means the field on disk is variable. Which means I can't just read a buffer size, pick the field out in memory, and move on.

This is because of #1 - I would need to accurately position the file pointer back to the character after #0 to accurately read the next record.

Now the only thing I'm thinking of that's possible is to start reading the field byte by byte until I hit #0. While this would work, it would have some performance issues attached to it (unless memory-mapping this file would negate that).

But since it's a null-terminated string I'd have to think there's an easier way to handle this. Am I on track with my idea or is there really an easier way to handle it?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Are you dictating the file-format?
If Yes, then either:
- Define the field as long as the longest found data + 1 (holding the #0)
- Build a list of filepointers pointing to all 1st bytes of each record (aka: An Index)
- Use a proper database

If No:
- Read each field as you find it, and count the number of fields per record, to know when to start a new record.
 
Actually no. If I could dictate the file format, I wouldn't have set this situation up to begin with.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
What about loading the file into a memory stream? One 'slow' read and then super-fast access. You can save the file periodically to the disk to retain changes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top