D styled data format, Json failed
Saaa
empty at needmail.com
Sun May 3 21:51:00 PDT 2009
I looked at the JSON format and it seems very inefficient at loading arrays
as it isn't limited to one type per array.
This is nice when you want to save a small array with different typed
elements but for my purposes this is kind of a performance problem.
This is why I will try and get suggestions again about the D-styled format I
tried to suggest a few threads ago :)
Let me suggest a simple example:
(Please tell me when something isn't obvious :)
---file.dat
//comment
int number = 10;
float [3][2] simpleArray = [
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6]];
--
---main.d
static import ddata;
void main()
{
char[][] file = read (`file.dat`);
int i;
char c;
ddata.get(file,'number',i);
ddata.get(file,'number',c); //type fail, thus returns -1 or throws an
exception
float [3][2] a;
ddata.get(file,'simpleArray',a);
ddata.write(file,'simpleArrayCopy', a);
a[0][0] =3.0;
ddata.write(file,'simpleArray', a);
write('file.dat', file);
}
--
resulting data file:
---file.dat
//comment
int number = 10;
float [3][2] simpleArray = [
[3.0, 0.2, 0.3],
[0.4, 0.5, 0.6]];
float [3][2] simpleArrayCopy = [
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6]];
--
More information about the Digitalmars-d-learn
mailing list