readstruct & writestruct
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
readstruct & writestruct
I am new so maybe I missed it. I have 2 items on my wishlist. One is a rehash of many suggestions before, but a multiline comment would be nice.
The other one I couldn't find in this forum is a way to read and write structures as unit to a file. I find readbyte, readword etc, but don't see an easy way to write a whole structure to a file as a unit. Am I missing it?
Thanks
John
The other one I couldn't find in this forum is a way to read and write structures as unit to a file. I find readbyte, readword etc, but don't see an easy way to write a whole structure to a file as a unit. Am I missing it?
Thanks
John
John R. Duchek
St. Louis,MO
St. Louis,MO
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
> a multiline comment would be nice.
to outcommend several lines of code:
mark the lines and press CTRL-B to outcommend them,
press Alt-B to remove the commending again.
> readstruct & writestruct
yap, thats a good idea. I'll second that request.
(I don't remember there is something like it, or is there?)
since a struct is like a Dataset/Recordset, it should be possible to read/write one in whole.
additional an adopted fileseek maybe nice,
but this can easily be solved via normal fileseek and SizeOf(struct) as multiplicator.
to outcommend several lines of code:
mark the lines and press CTRL-B to outcommend them,
press Alt-B to remove the commending again.
> readstruct & writestruct
yap, thats a good idea. I'll second that request.
(I don't remember there is something like it, or is there?)
since a struct is like a Dataset/Recordset, it should be possible to read/write one in whole.
additional an adopted fileseek maybe nice,
but this can easily be solved via normal fileseek and SizeOf(struct) as multiplicator.
oh... and have a nice day.
Code: Select all
Macro WriteStruct(File, Variable)
WriteData(File, @Variable, SizeOf(Variable))
EndMacro
Macro ReadStruct(File, Variable)
ReadData(File, @Variable, SizeOf(Variable))
EndMacro
- No strings
- If the name of the declared structured variable is also a structure name, then it will not work UNLESS the variable is of type structure name (because types have precedence over variables in SizeOf()).
Ok simple, i actually had an idea how to implement strings in there also. Would require a base header or at least some encapsulation method to ensure stringspace.
Thalius
Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!
"
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
to be used as a recordset, a string should have fixed length.
and fixed strings are within the structure, not in the pool.
PS:
@trond
nice macro, should fulfill it's purpose
and fixed strings are within the structure, not in the pool.
PS:
@trond
nice macro, should fulfill it's purpose

Last edited by Kaeru Gaman on Tue Apr 17, 2007 3:44 pm, edited 1 time in total.
oh... and have a nice day.
I've asked for something similar...
http://www.purebasic.fr/english/viewtopic.php?t=25121
Would be good.
http://www.purebasic.fr/english/viewtopic.php?t=25121
Would be good.
cheers,
bembulak
bembulak
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Each string structure has associated s_ data (basically a list of offsets to strings and other structures in a structure). Hopefully one day there will be a native command to access this data because it is useful for lots of things, e.g. clearing, comparing, copying and freeing structured memory containing strings - all of which is very useful when dealing when tree structures and skiplists and is laborious and error prone to code manually.
So this s_ data could also be used to code something that iterates through any structure and saves/loads string and non-string data if someone wants to attempt it but it would be a hack since the s_ data isn't natively available or documented.
So this s_ data could also be used to code something that iterates through any structure and saves/loads string and non-string data if someone wants to attempt it but it would be a hack since the s_ data isn't natively available or documented.
Mat
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
the problem is, that structures with dynamic strings are quite useless for building recordsets.
the main point of a recordset is a unique length for each set of the same structure.
this is the only point that makes fast recordset access in a file possible.
this kind of file is the grandfather of relational databases.
the dynamic strings are a pretty idea to save space in memory,
but it's even more difficult to write that to a file,
because then in the file each recordset will need previous/next-pointers like a linked-list has,
and you will have to browse the file from beginning setwise to find your desired recordset.
in the end I would say: decide!
if you want a convenient and small solution for memory, you'll have to write or read the complete list at once and handle it within memory.
if you want a tabellaric file, use fixlenth strings in your structure.
the main point of a recordset is a unique length for each set of the same structure.
this is the only point that makes fast recordset access in a file possible.
this kind of file is the grandfather of relational databases.
the dynamic strings are a pretty idea to save space in memory,
but it's even more difficult to write that to a file,
because then in the file each recordset will need previous/next-pointers like a linked-list has,
and you will have to browse the file from beginning setwise to find your desired recordset.
in the end I would say: decide!
if you want a convenient and small solution for memory, you'll have to write or read the complete list at once and handle it within memory.
if you want a tabellaric file, use fixlenth strings in your structure.
oh... and have a nice day.
The original post just asks for a way to dump and restore structured memory. Iteration can be performed via pointers to next/previous element as mentioned or if fast random access is required then an index can be built (for example CHM uses this where each record cannot be the same size) but i think this is overcomplicating it.
Mat