Erlang -- registry

Erl_Interface

Reference Manual

Version 3.13.1

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- ei
  - Top of manual page
  - ei_decode_atom()
  - ei_decode_atom_as()
  - ei_decode_bignum()
  - ei_decode_binary()
  - ei_decode_bitstring()
  - ei_decode_boolean()
  - ei_decode_char()
  - ei_decode_double()
  - ei_decode_ei_term()
  - ei_decode_fun()
  - ei_decode_list_header()
  - ei_decode_long()
  - ei_decode_longlong()
  - ei_decode_map_header()
  - ei_decode_pid()
  - ei_decode_port()
  - ei_decode_ref()
  - ei_decode_string()
  - ei_decode_term()
  - ei_decode_trace()
  - ei_decode_tuple_header()
  - ei_decode_ulong()
  - ei_decode_ulonglong()
  - ei_decode_version()
  - ei_encode_atom()
  - ei_encode_atom_as()
  - ei_encode_atom_len()
  - ei_encode_atom_len_as()
  - ei_encode_bignum()
  - ei_encode_binary()
  - ei_encode_bitstring()
  - ei_encode_boolean()
  - ei_encode_char()
  - ei_encode_double()
  - ei_encode_empty_list()
  - ei_encode_fun()
  - ei_encode_list_header()
  - ei_encode_long()
  - ei_encode_longlong()
  - ei_encode_map_header()
  - ei_encode_pid()
  - ei_encode_port()
  - ei_encode_ref()
  - ei_encode_string()
  - ei_encode_string_len()
  - ei_encode_term()
  - ei_encode_trace()
  - ei_encode_tuple_header()
  - ei_encode_ulong()
  - ei_encode_ulonglong()
  - ei_encode_version()
  - ei_get_type()
  - ei_init()
  - ei_print_term()
  - ei_s_print_term()
  - ei_set_compat_rel()
  - ei_skip_term()
  - ei_x_append()
  - ei_x_append_buf()
  - ei_x_encode_atom()
  - ei_x_encode_atom_as()
  - ei_x_encode_atom_len()
  - ei_x_encode_atom_len_as()
  - ei_x_encode_bignum()
  - ei_x_encode_binary()
  - ei_x_encode_bitstring()
  - ei_x_encode_boolean()
  - ei_x_encode_char()
  - ei_x_encode_double()
  - ei_x_encode_empty_list()
  - ei_x_encode_fun()
  - ei_x_encode_list_header()
  - ei_x_encode_long()
  - ei_x_encode_longlong()
  - ei_x_encode_map_header()
  - ei_x_encode_pid()
  - ei_x_encode_port()
  - ei_x_encode_ref()
  - ei_x_encode_string()
  - ei_x_encode_string_len()
  - ei_x_encode_term()
  - ei_x_encode_trace()
  - ei_x_encode_tuple_header()
  - ei_x_encode_ulong()
  - ei_x_encode_ulonglong()
  - ei_x_encode_version()
  - ei_x_format()
  - ei_x_format_wo_ver()
  - ei_x_free()
  - ei_x_new()
  - ei_x_new_with_version()
  - free_fun()
- ei_connect
  - Top of manual page
  - ei_accept()
  - ei_accept_tmo()
  - ei_close_connection()
  - ei_connect()
  - ei_connect_init()
  - ei_connect_init_ussi()
  - ei_connect_tmo()
  - ei_connect_xinit()
  - ei_connect_xinit_ussi()
  - ei_get_tracelevel()
  - ei_gethostbyaddr()
  - ei_gethostbyaddr_r()
  - ei_gethostbyname()
  - ei_gethostbyname_r()
  - ei_listen()
  - ei_publish()
  - ei_publish_tmo()
  - ei_receive()
  - ei_receive_encoded()
  - ei_receive_encoded_tmo()
  - ei_receive_msg()
  - ei_receive_msg_tmo()
  - ei_receive_tmo()
  - ei_reg_send()
  - ei_reg_send_tmo()
  - ei_rpc()
  - ei_rpc_from()
  - ei_rpc_to()
  - ei_self()
  - ei_send()
  - ei_send_encoded()
  - ei_send_encoded_tmo()
  - ei_send_reg_encoded()
  - ei_send_reg_encoded_tmo()
  - ei_send_tmo()
  - ei_set_tracelevel()
  - ei_thisalivename()
  - ei_thishostname()
  - ei_thisnodename()
  - ei_unpublish()
  - ei_unpublish_tmo()
  - ei_xconnect()
  - ei_xconnect_tmo()
  - ei_xlisten()
  - ei_xreceive_msg()
  - ei_xreceive_msg_tmo()
- registry
  - Top of manual page
  - ei_reg_close()
  - ei_reg_delete()
  - ei_reg_dump()
  - ei_reg_getfval()
  - ei_reg_getival()
  - ei_reg_getpval()
  - ei_reg_getsval()
  - ei_reg_getval()
  - ei_reg_markdirty()
  - ei_reg_open()
  - ei_reg_purge()
  - ei_reg_resize()
  - ei_reg_restore()
  - ei_reg_setfval()
  - ei_reg_setival()
  - ei_reg_setpval()
  - ei_reg_setsval()
  - ei_reg_setval()
  - ei_reg_stat()
  - ei_reg_tabstat()
- erl_connect
  - Top of manual page
  - erl_accept()
  - erl_close_connection()
  - erl_connect()
  - erl_connect_init()
  - erl_connect_xinit()
  - erl_gethostbyaddr()
  - erl_gethostbyaddr_r()
  - erl_gethostbyname()
  - erl_gethostbyname_r()
  - erl_publish()
  - erl_receive()
  - erl_receive_msg()
  - erl_reg_send()
  - erl_rpc()
  - erl_rpc_from()
  - erl_rpc_to()
  - erl_send()
  - erl_thisalivename()
  - erl_thiscookie()
  - erl_thiscreation()
  - erl_thishostname()
  - erl_thisnodename()
  - erl_unpublish()
  - erl_xconnect()
  - erl_xreceive_msg()
- erl_error
  - Top of manual page
  - erl_err_msg()
  - erl_err_quit()
  - erl_err_ret()
  - erl_err_sys()
  - erl_errno()
- erl_eterm
  - Top of manual page
  - erl_cons()
  - erl_copy_term()
  - erl_element()
  - erl_hd()
  - erl_init()
  - erl_iolist_length()
  - erl_iolist_to_binary()
  - erl_iolist_to_string()
  - erl_length()
  - erl_mk_atom()
  - erl_mk_binary()
  - erl_mk_empty_list()
  - erl_mk_estring()
  - erl_mk_float()
  - erl_mk_int()
  - erl_mk_list()
  - erl_mk_long_ref()
  - erl_mk_pid()
  - erl_mk_port()
  - erl_mk_ref()
  - erl_mk_string()
  - erl_mk_tuple()
  - erl_mk_uint()
  - erl_mk_var()
  - erl_print_term()
  - erl_set_compat_rel()
  - erl_size()
  - erl_tl()
  - erl_var_content()
- erl_format
  - Top of manual page
  - erl_format()
  - erl_match()
- erl_global
  - Top of manual page
  - erl_global_names()
  - erl_global_register()
  - erl_global_unregister()
  - erl_global_whereis()
- erl_malloc
  - Top of manual page
  - erl_alloc_eterm()
  - erl_eterm_release()
  - erl_eterm_statistics()
  - erl_free()
  - erl_free_array()
  - erl_free_compound()
  - erl_free_term()
  - erl_malloc()
- erl_marshal
  - Top of manual page
  - erl_compare_ext()
  - erl_decode()
  - erl_decode_buf()
  - erl_encode()
  - erl_encode_buf()
  - erl_ext_size()
  - erl_ext_type()
  - erl_peek_ext()
  - erl_term_len()
- erl_call

# registry

### C Library

registry

### Library Summary

Store and back up key-value pairs.

### Description

This module provides support for storing key-value pairs in a table known as a registry, backing up registries to Mnesia in an atomic manner, and later restoring the contents of a registry from Mnesia.

### Exports

int ei_reg_close( reg) |

### Types

ei_reg *reg;

A registry that has previously been created with ei_reg_open() is closed, and all the objects it contains are freed.

reg is the registry to close.

Returns 0.

int ei_reg_delete( reg, key) |

### Types

ei_reg *reg;
const char *key;

Deletes an object from the registry. The object is not removed from the registry, it is only marked for later removal so that on later backups to Mnesia, the corresponding object can be removed from the Mnesia table as well. If another object is later created with the same key, the object will be reused.

The object is removed from the registry after a call to ei_reg_dump() or ei_reg_purge().

- reg is the registry containing key.
- key is the object to remove.

Returns 0 on success, otherwise -1.

int ei_reg_dump( fd, reg, mntab, flags) |

### Types

int fd;
ei_reg *reg;
const char *mntab;
int flags;

Dumps the contents of a registry to a Mnesia table in an atomic manner, that is, either all data or no data is updated. If any errors are encountered while backing up the data, the entire operation is aborted.

- fd is an open connection to Erlang. Mnesia 3.0 or later must be running on the Erlang node.
- reg is the registry to back up.
- mntab is the name of the Mnesia table where the backed up data is to be placed. If the table does not exist, it is created automatically using configurable defaults. For information about configuring this behavior, see Mnesia.

If flags is 0, the backup includes only those objects that have been created, modified, or deleted since the last backup or restore (that is, an incremental backup). After the backup, any objects that were marked dirty are now clean, and any objects that had been marked for deletion are deleted.

Alternatively, setting flags to EI_FORCE causes a full backup to be done, and EI_NOPURGE causes the deleted objects to be left in the registry afterwards. These can be bitwise OR'ed together if both behaviors are desired. If EI_NOPURGE was specified, ei_reg_purge() can be used to explicitly remove the deleted items from the registry later.

Returns 0 on success, otherwise -1.

double ei_reg_getfval( reg, key) |

### Types

ei_reg *reg;
const char *key;

Gets the value associated with key in the registry. The value must be a floating point type.

- reg is the registry where the object will be looked up.
- key is the name of the object to look up.

On success, the function returns the value associated with key. If the object is not found or if it is not a floating point object, -1.0 is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between -1.0 and a valid result), use the more general function ei_reg_getval() instead.

int ei_reg_getival( reg, key) |

### Types

ei_reg *reg;
const char *key;

Gets the value associated with key in the registry. The value must be an integer.

- reg is the registry where the object will be looked up.
- key is the name of the object to look up.

On success, the function returns the value associated with key. If the object is not found or if it is not an integer object, -1 is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between -1 and a valid result), use the more general function ei_reg_getval() instead.

const void *ei_reg_getpval( reg, key, size) |

### Types

ei_reg *reg;
const char *key;
int size;

Gets the value associated with key in the registry. The value must be a binary (pointer) type.

- reg is the registry where the object will be looked up.
- key is the name of the object to look up.
- size is initialized to contain the length in bytes of the object, if it is found.

On success, the function returns the value associated with key and indicates its length in size. If the object is not found or if it is not a binary object, NULL is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between NULL and a valid result), use the more general function ei_reg_getval() instead.

const char *ei_reg_getsval( reg, key) |

### Types

ei_reg *reg;
const char *key;

Gets the value associated with key in the registry. The value must be a string.

- reg is the registry where the object will be looked up.
- key is the name of the object to look up.

On success, the function returns the value associated with key. If the object is not found or if it is not a string, NULL is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between NULL and a valid result), use the more general function ei_reg_getval() instead.

int ei_reg_getval( reg, key, flags, v, ...) |

### Types

ei_reg *reg;
const char *key;
int flags;
void *v (see below)

A general function for retrieving any kind of object from the registry.

- reg is the registry where the object will be looked up.

- key is the name of the object to look up.

- flags indicates the type of object that you are looking for. If flags is 0, any kind of object is returned. If flags is EI_INT, EI_FLT, EI_STR, or EI_BIN, then only values of that kind are returned.

  The buffer pointed to by v must be large enough to hold the return data, that is, it must be a pointer to one of int, double, char*, or void*, respectively.

  If flags is EI_BIN, a fifth argument int *size is required, so that the size of the object can be returned.

On success, v (and size if the object is binary) is initialized with the value associated with key, and the function returns EI_INT, EI_FLT, EI_STR, or EI_BIN, indicating the type of object. On failure, -1 is returned and the arguments are not updated.

int ei_reg_markdirty( reg, key) |

### Types

ei_reg *reg;
const char *key;

Marks a registry object as dirty. This ensures that it is included in the next backup to Mnesia. Normally this operation is not necessary, as all of the normal registry 'set' functions do this automatically. However, if you have retrieved the value of a string or binary object from the registry and modified the contents, then the change is invisible to the registry and the object is assumed to be unmodified. This function allows you to make such modifications and then let the registry know about them.

- reg is the registry containing the object.
- key is the name of the object to mark.

Returns 0 on success, otherwise -1.

ei_reg *ei_reg_open( size) |

### Types

int size;

Opens (creates) a registry, which initially is empty. To close the registry later, use ei_reg_close().

size is the approximate number of objects you intend to store in the registry. As the registry uses a hash table with collision chaining, no absolute upper limit exists on the number of objects that can be stored in it. However, for reasons of efficiency, it is a good idea to choose a number that is appropriate for your needs. To change the size later, use ei_reg_resize(). Notice that the number you provide is increased to the nearest larger prime number.

Returns an empty registry on success, otherwise NULL.

int ei_reg_purge( reg) |

### Types

ei_reg *reg;

Removes all objects marked for deletion. When objects are deleted with ei_reg_delete() they are not removed from the registry, only marked for later removal. On a later backup to Mnesia, the objects can also be removed from the Mnesia table. If you are not backing up to Mnesia, you may wish to remove the objects manually with this function.

reg is a registry containing objects marked for deletion.

Returns 0 on success, otherwise -1.

int ei_reg_resize( reg, newsize) |

### Types

ei_reg *reg;
int newsize;

Changes the size of a registry.

newsize is the new size to make the registry. The number is increased to the nearest larger prime number.

On success, the registry is resized, all contents rehashed, and 0 is returned. On failure, the registry is left unchanged and -1 is returned.

int ei_reg_restore( fd, reg, mntab) |

### Types

int fd;
ei_reg *reg;
const char *mntab;

The contents of a Mnesia table are read into the registry.

- fd is an open connection to Erlang. Mnesia 3.0 or later must be running on the Erlang node.
- reg is the registry where the data is to be placed.
- mntab is the name of the Mnesia table to read data from.

Notice that only tables of a certain format can be restored, that is, those that have been created and backed up to with ei_reg_dump(). If the registry was not empty before the operation, the contents of the table are added to the contents of the registry. If the table contains objects with the same keys as those already in the registry, the registry objects are overwritten with the new values. If the registry contains objects that were not in the table, they are unchanged by this operation.

After the restore operation, the entire contents of the registry is marked as unmodified. Notice that this includes any objects that were modified before the restore and not overwritten by the restore.

Returns 0 on success, otherwise -1.

int ei_reg_setfval( reg, key, f) |

### Types

ei_reg *reg;
const char *key;
double f;

Creates a key-value pair with the specified key and floating point value f. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

- reg is the registry where the object is to be placed.
- key is the object name.
- f is the floating point value to assign.

Returns 0 on success, otherwise -1.

int ei_reg_setival( reg, key, i) |

### Types

ei_reg *reg;
const char *key;
int i;

Creates a key-value pair with the specified key and integer value i. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

- reg is the registry where the object is to be placed.
- key is the object name.
- i is the integer value to assign.

Returns 0 on success, otherwise -1.

int ei_reg_setpval( reg, key, p, size) |

### Types

ei_reg *reg;
const char *key;
const void *p;
int size;

Creates a key-value pair with the specified key whose "value" is the binary object pointed to by p. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

- reg is the registry where the object is to be placed.
- key is the object name.
- p is a pointer to the binary object. The object itself must have been created through a single call to malloc() or a similar function, so that the registry can later delete it if necessary by calling free().
- size is the length in bytes of the binary object.

Returns 0 on success, otherwise -1.

int ei_reg_setsval( reg, key, s) |

### Types

ei_reg *reg;
const char *key;
const char *s;

Creates a key-value pair with the specified key whose "value" is the specified string s. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

- reg is the registry where the object is to be placed.
- key is the object name.
- s is the string to assign. The string itself must have been created through a single call to malloc() or similar a function, so that the registry can later delete it if necessary by calling free().

Returns 0 on success, otherwise -1.

int ei_reg_setval( reg, key, flags, v, ...) |

### Types

ei_reg *reg;
const char *key;
int flags;
v (see below)

Creates a key-value pair with the specified key whose value is specified by v. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

- reg is the registry where the object is to be placed.

- key is the object name.

- flags indicates the type of the object specified by v. Flags must be one of EI_INT, EI_FLT, EI_STR, and EI_BIN, indicating whether v is int, double, char*, or void*.

  If flags is EI_BIN, a fifth argument size is required, indicating the size in bytes of the object pointed to by v.

If you wish to store an arbitrary pointer in the registry, specify a size of 0. In this case, the object itself is not transferred by an ei_reg_dump() operation, only the pointer value.

Returns 0 on success, otherwise -1.

int ei_reg_stat( reg, key, obuf) |

### Types

ei_reg *reg;
const char *key;
struct ei_reg_stat *obuf;

Returns information about an object.

- reg is the registry containing the object.
- key is the object name.
- obuf is a pointer to an ei_reg_stat structure, defined as follows:

    struct ei_reg_stat {
      int attr;
      int size;
    };

In attr the attributes of the object are stored as the logical OR of its type (one of EI_INT, EI_FLT, EI_BIN, and EI_STR), whether it is marked for deletion (EI_DELET), and whether it has been modified since the last backup to Mnesia (EI_DIRTY).

Field size indicates the size in bytes required to store EI_STR (including the terminating 0) and EI_BIN objects, or 0 for EI_INT and EI_FLT.

Returns 0 and initializes obuf on success, otherwise -1.

int ei_reg_tabstat( reg, obuf) |

### Types

ei_reg *reg;
struct ei_reg_tabstat *obuf;

Returns information about a registry. Using information returned by this function, you can see whether the size of the registry is suitable for the amount of data it contains.

- reg is the registry to return information about.
- obuf is a pointer to an ei_reg_tabstat structure, defined as follows:

    struct ei_reg_tabstat {
      int size;
      int nelem;
      int npos;
      int collisions;
    };

Field size indicates the number of hash positions in the registry. This is the number you provided when you created or last resized the registry, rounded up to the nearest prime number.

- nelem indicates the number of elements stored in the registry. It includes objects that are deleted but not purged.
- npos indicates the number of unique positions that are occupied in the registry.
- collisions indicates how many elements are sharing positions in the registry.

On success, 0 is returned and obuf is initialized to contain table statistics, otherwise -1 is returned.