rspamd_mempool
Rspamd memory pool is used to allocate memory attached to specific objects, namely it was initially used for memory allocation for rspamd_task.
All memory allocated by the pool is destroyed when the associated object is destroyed. This allows a sort of controlled garbage collection for memory allocated from the pool. Memory pools are extensively used by rspamd internal components and provide some powerful features, such as destructors or persistent variables.
Functions:
Function | Description |
---|---|
mempool.create([size]) |
Creates a memory pool of a specified size or platform dependent optimal size (normally, a page size). |
Methods:
Method | Description |
---|---|
mempool:add_destructor(func) |
Adds new destructor function to the pool. |
mempool:destroy() |
Destroys memory pool cleaning all variables and calling all destructors registered (both C and Lua ones). |
mempool:set_variable(name, [value1[, value2 ...]]) |
Sets a variable that’s valid during memory pool lifetime. |
mempool:set_bucket(name, num_values, [value1...valuen]|[table]) |
Stores a variable bucket of numbers where the first number is number of elements to pack. |
mempool:get_variable(name[, type]) |
Unpacks mempool variable to lua If type is not specified, then a variable is. |
mempool:has_variable(name) |
Checks if the specified variable name exists in the memory pool. |
mempool:delete_variable(name) |
Removes the specified variable name from the memory pool. |
The module rspamd_mempool
defines the following functions.
mempool.create([size])
Creates a memory pool of a specified size
or platform dependent optimal size (normally, a page size)
Parameters:
size {number}
: size of a page inside poolReturns:
{rspamd_mempool}
: new pool object (that should be removed by explicit call to pool:destroy()
)Back to module description.
The module rspamd_mempool
defines the following methods.
mempool:add_destructor(func)
Adds new destructor function to the pool
Parameters:
func {function}
: function to be called when the pool is destroyedReturns:
No return
Back to module description.
mempool:destroy()
Destroys memory pool cleaning all variables and calling all destructors registered (both C and Lua ones)
Parameters:
No parameters
Returns:
No return
Back to module description.
mempool:set_variable(name, [value1[, value2 ...]])
Sets a variable that’s valid during memory pool lifetime. This function allows to pack multiple values inside a single variable. Currently supported types are:
string
: packed as null terminated C string (so no \0
are allowed)number
: packed as C doubleboolean
: packed as boolParameters:
name {string}
: variable’s name to setReturns:
No return
Back to module description.
mempool:set_bucket(name, num_values, [value1...valuen]|[table])
Stores a variable bucket of numbers where the first number is number of elements to pack and then there should be either n numeric values or a plain table of numeric values
Parameters:
name {string}
: variable’s name to setnum_values {number}
: number of variables in the bucketvalues {table|list}
: valuesReturns:
No return
Back to module description.
mempool:get_variable(name[, type])
Unpacks mempool variable to lua If type
is not specified, then a variable is
assumed to be zero-terminated C string. Otherwise, type
is a comma separated (spaces are ignored)
list of types that should be unpacked from a variable’s content. The following types
are supported:
string
: null terminated C string (so no \0
are allowed)double
: returned as lua numberint
: unpack a single integerint64
: unpack 64-bits integerboolean
: unpack booleanbucket
: bucket of numbers represented as a Lua tablefstrings
: list of rspamd_fstring_t (GList) represented as a Lua tableParameters:
name {string}
: variable’s name to gettype {string}
: list of types to be extractedReturns:
{variable list}
: list of variables extracted (but not a table)Back to module description.
mempool:has_variable(name)
Checks if the specified variable name
exists in the memory pool
Parameters:
name {string}
: variable’s name to getReturns:
{boolean}
: true
if variable exists and false
otherwiseBack to module description.
mempool:delete_variable(name)
Removes the specified variable name
from the memory pool
Parameters:
name {string}
: variable’s name to removeReturns:
{boolean}
: true
if variable exists and has been removedBack to module description.
Back to top.