WORD PTR

Pointed Development

Let's Write a Linux Daemon - Part III

| Comments

This is Part III in a series. Check out the rest of the series:

As with all of the source code on this blog, I’ve pushed everything up to github under the repository. You can retrieve the latest like so:

git clone git://github.com/jgshort/wordptr.git

First, tl;dr:

  • strings; memory pool

Quick Update

This is just a quick update on the code I’ve committed to the github repository this weekend. There is nothing new or revolutionary in the code pushed to github: I’ve added the interface for a string class and an interface for a memory pool. Neither class is fully fleshed out and contain bugs and incomplete implementations… But they’re present.

Effectively, I simply wasn’t satisfied with the interfaces of some of the string libraries I’ve found so far – I’m completely open to suggestions, though – as always! I have specific requirements for this daemon and interning (or atomization) and immutability are key, as well as fast string length and hash functions. The memory pool class is ultimately a consequence of the current string design and may change or go away.

Here’s the current nmc_string_t interface as it stands today. This is likely going to change:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typedef struct nmc_string {
  nmc_status_t (*copy)(struct nmc_string **self_out, const struct nmc_string *src);
  nmc_status_t (*copy_to_pool)(struct nmc_string **self_out, const nmc_pool_t *pool, const struct nmc_string *src);

  bool (*equals)(const struct nmc_string *self, const struct nmc_string *to);
  int (*compare)(const struct nmc_string *self, const struct nmc_string *to);

  const char *(*get_str)(const struct nmc_string *self);
  size_t (*get_length)(const struct nmc_string *self);
  int (*get_hash)(const struct nmc_string *self);
  int (*get_ref_count)(const struct nmc_string *self);
  nmc_pool_t *(*get_pool)(const struct nmc_string *self);

  nmc_status_t (*concat)(const struct nmc_string *self, struct nmc_string **self_out, ...);
  nmc_status_t (*substr)(const struct nmc_string *self, struct nmc_string **self_out, int index, size_t len);

  struct nmc_string *(*ltrim)(const struct nmc_string *self);
  struct nmc_string *(*rtrim)(const struct nmc_string *self);
  struct nmc_string *(*trim)(const struct nmc_string *self);

  nmc_string_private_t data;
} nmc_string_t;

I’m not sure. This whole application is a complete work in progress.

Which string handling library do you utilize? Any memory pool suggestions? I’ve looked into APR and the verdict is still out.

Thanks for following along!

References

Comments