"jason" <ji***@notmal.c omwrote in message
news:47******** *************** @dreader21.news .xs4all.nl...
Hello,
I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
....
I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used in
this field. x->row[i].coll[0].utype ;
However in my inexperience I forgot that most of the functions I want to
use on this data accept arrays only - Now I have added an extra step to
create an array of pointers linking to all the values in the
collumn.unions.
When I think of it [what I should have done before starting to program] I
have three choices;
Leave it this way disregarding the extra overhead of creating an array of
pointers, but maintaining all the preferences of each field.
Remove the union and create void pointers
or at runtime create an array for each collumn and a `super' structure
that holds all the preferences of each collumn.
Again I'm not very experienced with this - but what would be the best way
to go for storing this type of data in such way that it becomes easy to
preform operations on it ?
Any suggestions are welcome.
this depends on what you are doing...
however, here are a few typical ways to deal with 2D grids of values:
a 2D array (say, of pointers);
a 1D array indexing 1D arrays;
a custom representation (say, the above, but combined with a sequence of
"spans" or similar for applying in-memory compression);
....
a 2D array is good for speed and simplicity, and can also be memory
efficient (if the data is strictly a grid), but it can become very slow to
resize or also very wasteful with memory in some cases.
a 1D array of 1D arrays adds a little more complexity and overhead, but can
make dynamic resizing a lot faster and easier (adding an item often only
involves expanding 1 or 2 of these arrays).
a pair of arrays with a system of 'spans' is useful for when items are
spread sparsely over a large area, as this allows storing a fairly large
space in a comparatively small number of array spots. however, this adds yet
more complexity.
value:
this depends again very highly on usage.
if the values are usually or almost always the same type, and there is
little or no variation is the size, a slab may be a good option. this is an
array of items (say, structs), where we grab off items as needed and use
them where needed (usually a method exists for fairly quickly finding free
items, with linear allocation, marks+rovers, and free-lists being common
approaches).
it types are far more hetrogeneous (one item may be an integer, a float, a
string, another array, an object, ...) implementing some kind of dynamic
type system may be sensible.
for example, each item is an integer with a few low bits used to indicate
type, with the rest being either a value, a pointer, or a handle.
another approach is to use pointers, but implement a system for finding
types associated with pointers (for example, hidden object headers, having
the pointers point into 'special' areas of memory known to represent items
of specific types, ...).
and there are many other factors...
or such...
Thank you.
Jas.