A tutorial of the costs of dealing with data using Vstr

This page is an advanced tutorial looking at the costs of the different Vstr calls, given different data. For a simpler starting tutorial see this page.

Moving data between Vstr_base objects

There are five basic methods of moving data from one Vstr to another:

Deleting data from a Vstr_base object

There is only a single call to delete data from a Vstr, vstr_del(), however it has different speed characteristics depending on what it needs to delete. Much like vstr_mov() the worst case is dealing with data that doesn't go to the end of a _BUF node, with a single exception. This requires a single memmove() of all the later data in the node to the start of the deletion in that node. All node types can delete data form the end of the node by just changing a variable, nodes can be entirely removed by changing pointers (although removing pointers from the middle of the Vstr will destroy the iovec cache -- but that shouldn't be a large hit). All nodes, apart from _BUF, can delete data from the begining of the node ... and there is an optimisation so that deleting from the begining of _BUF nodes directly at the begining of the Vstr requires only a variable alteration (this is a common operation for IO, add at the end and delete from the begining).

Deleteing from the middle of a non _BUF node is a somewhat faster way of doing a delete to the end of the node and then an _ADD. Tht means that this requires an allocation, which is why vstr_del() returns a SUCCESS or FAILURE. This also applies to _BUF nodes when the VSTR_CNTL_CONF_GET_FLAG_DEL_SPLIT attribute is set in the configuration.


James Antill
Last modified: Mon Jan 26 05:09:10 EST 2004