BenLunt wrote:Hi,
Something that I haven't seen "spoken" of here very much is a kernel registry, some way to keep information available using a kernel call.
Kernels are about mechanism. This information looks more like policy, which I personally think lives in user land.
For example, POSIX kernels provide security mechanisms with almost no policy (based on separation of processes and access conrol based on user ids), but the act of logging in using a user name and authenticating that user is policy, and done entirely in user space.
BenLunt wrote:
For example, an application may want to store the top-left pixel position at close time so that it can use that same position when it loads next time. Something like:
Code: Select all
"kernel/ApplicationName/Main/Window/Top = 100"
"kernel/ApplicationName/Main/Window/Left = 100"
I think XML would be a good source to do this, but decided to make my own using my own format.
Because, why not? We're all here because we like re-implementing things
This is also probably a bad example though. An application could simply save such information in an application specific manner (such as an .ini file), or use a system provided library to store the application data in an application specific registry hive/location, and get all these benefits.
* No synchronized access to some shared resource required.
* Maintaining settings in memory for applications that are not even running is not required
BenLunt wrote:
To create the two entries above, a couple of calls such as:
Code: Select all
registry_write_int("/Kernel/ApplicationName/Main/Window/Top", 100);
registry_write_int("/Kernel/ApplicationName/Main/Window/Left", 100);
To retrieve a value:
Code: Select all
int ret = 0, Left;
ret = registry_read_int("/Kernel/ApplicationName/Main/Window/Top", &Left);
if (ret == sizeof(int))
; // Left now contains the value of 100
Anyway, if you are interested in what I have come up with,
have a look here.
A (drop-in) demo/skeleton source code is included. The main idea was to be simple and easy to use. The code is currently experimental since I haven't tested it thoroughly. Comments are welcome.
How/when should the values be persisted?
Presumably, a user level process could maintain the persistence on an ongoing basis, but the format doesn't look like it is very friendly for incremental updates, it looks like an all or nothing write of the entire registry contents.
Incremental updates could, however, be achieved by splitting the structure of the register hives, and the values in the hives.
So, when writing the registry file, you write:
- Root hive details (id=1)
- Child hive details (parent hive id=1, id=2)
- Child hive details (parent hive id=1, id=3)
- Grandchild hive details (parent hive id=3, id=4)
- Value in root hive (hive id=1, value id=5)
- Value in child hive (hive id=2, value id=6)
- Value in grandchild hive (hive id=4, value id=7)
- Value in root hive replacing original value (hive id=1, value id=5)
You can then stream the file sequentially, building up the in-memory registry based on the structure implied by the ids. Later values with the same ids as earlier values overwrite those earlier values, allowing incremental updates, making the registry more like an append only log. Very robust (no data is overwritten) and speedy (only write value changes) at the cost of having to compact the log every now and then. Each entry can have it's own checksum, so invalid entries can be detected and skipped, but you'd need some mechanism to resynchronize the stream if you want to recover values after an error.