Quote Originally Posted by marcelo.br View Post
Ok, if it doesn't work with struct and not with matrix.
Is there something else I could use in C that would work?

Because there are fields that are extremely huge, and others that take only a few bytes.

And it would be a huge waste of memory for me to allocate for example 500Mb of memory for all the records, since most of them will use 100 bytes!

Example: A database with 1000 records
Record 1:
Title field: Uses 100 bytes
Description Field: Using 500Mb

Record 2:
Title Field: Expends 90 Bytes
Description Field: Expending 200 Bytes

Just think, I will have to allocate 1000 x 500Mb bytes just because out of these 1000 records some 20 use 500Mb or some 980 use very few bytes!

If I can't use struct, nor matrix, how can I do this?
If you look closely at that last code I suppled, it does let you do what you want.

* The memory for each field is mallc()ed, and can be any size.

* A record has 6 fields.

* You can malloc() (and maybe realloc()) storage for as many records as you require for your dataset.

So each record needs storage for 6 pointers (48 bytes), and the storage allocated for it's fields, plus 7 times the overhead required by your malloc() implementation (e.g. something like 8 bytes per allocation)