B
Bill Reid
I was stupidly fooling around over the weekend converting some
code I wrote a long time ago for a database schema into something
more like a "linked list" or actually a linked "tree". Everything seemed
to work OK, such as traversing the tree from any branch and
from any node, EXCEPT for some reason the "tree" memory,
which is currently a contiguously allocated ordered block during
database initialization, is apparently over-writing another
contiguously allocated block in the same schema structure,
which is messing up a few descriptive strings in weird and
varying ways.
Here's how I declared the offending database "linked" node:
struct DB_Node {
struct DB_Node *parent;
struct DB_Node *child;
struct DB_Node *previous;
struct DB_Node *next;
struct DB_Category *category;
unsigned order;
};
I mean, this is perfectly legal, right? The strange thing is that if
I rearrange the structure elements I get different results, but always
in some way some strings in the *category block, which is allocated
completely separately and written with strings at an earlier point, get
screwed up at some point as I assign each node values for *previous,
etc., either NULL or the address of the "linked" node, based on an
initialization file. The *category strings are either missing, or contain
garbage, depending on the number of nodes initialized AND the order
of the DB_Node structure elements.
Does this ring any immediate bells for anybody, something
fundamental I'm missing? Like I say, the "linked tree" itself
apparently works fine for traversing, etc., but when I display
the schema some of the descriptive strings are messed up
or just plain missing, and I've localized the problem to
an area in the node initialization loop...
code I wrote a long time ago for a database schema into something
more like a "linked list" or actually a linked "tree". Everything seemed
to work OK, such as traversing the tree from any branch and
from any node, EXCEPT for some reason the "tree" memory,
which is currently a contiguously allocated ordered block during
database initialization, is apparently over-writing another
contiguously allocated block in the same schema structure,
which is messing up a few descriptive strings in weird and
varying ways.
Here's how I declared the offending database "linked" node:
struct DB_Node {
struct DB_Node *parent;
struct DB_Node *child;
struct DB_Node *previous;
struct DB_Node *next;
struct DB_Category *category;
unsigned order;
};
I mean, this is perfectly legal, right? The strange thing is that if
I rearrange the structure elements I get different results, but always
in some way some strings in the *category block, which is allocated
completely separately and written with strings at an earlier point, get
screwed up at some point as I assign each node values for *previous,
etc., either NULL or the address of the "linked" node, based on an
initialization file. The *category strings are either missing, or contain
garbage, depending on the number of nodes initialized AND the order
of the DB_Node structure elements.
Does this ring any immediate bells for anybody, something
fundamental I'm missing? Like I say, the "linked tree" itself
apparently works fine for traversing, etc., but when I display
the schema some of the descriptive strings are messed up
or just plain missing, and I've localized the problem to
an area in the node initialization loop...