Re: R: R: R: R: [AD] Allegro 5 new config routines, alpha 1

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Angelo Mottola wrote:

[snip]

I'll summarize our current problem here: we have the following decision
to take. We can:

1) Store variables in memory using their real type. An int is stored as
an int, etc.
Pro: fast access to the variable once it's already in memory, as no type
conversion is involved.
Con: the data type is apparently (if we don't find a way to solve it)
lost when saving the variables to disk.



I'm assuming here that reading speed is more important than writting speed.
Couldn't you have two flags in your config entry, the first one being the type of the last write (bool, hex, etc), and the second one being the formats it was converted to.

Then, the read functions would look like:

int al_get_int(char *key, int default) {
    ENTRY *entry = read_entry(key);

    if (!(entry->converted_to & CONFIG_TYPE_INT)) {
       convert_to_int(entry);
       entry->converted_to |= CONFIG_TYPE_INT);
    }
    return entry->int;
}

and the write functions:

int al_set_int(char *key, int val) {
    ENTRY *entry = write_entry(key);

    entry->int = val;
    entry->converted_to = CONFIG_TYPE_INT;
    entry->original_type = CONFIG_TYPE_INT;
}

Idealy, the hash table would also be able to optimize itself so that the most often accessed entries get the least amount of re-hashing.
--
- Robert J Ohannessian
"Microsoft code is probably O(n^20)" (my CS prof)
http://pages.infinit.net/voidstar/



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/