1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-16 01:26:18 +02:00

lib: introduce ByteVector as a replacement for vector<uint8_t> and Spanner

After some benchmarking, it turns out that std::vector<uint8_t> is
about 160 times slower than malloc().  malloc() is faster than "new
uint8_t[]" too.  Get rid of std:;vector<uint8_t> and replace it with
a lightweight wrapper around malloc(), free(), and memcpy().

ByteVector has helpful methods for the common case of moving data to and
from ioctl calls that use a fixed-length header placed contiguously with a
variable-length input/output buffer.  Data bytes are shared between copied
ByteVector objects, allowing a large single buffer to be cheaply chopped
up into smaller objects without memory copies.  ByteVector implements the
more useful parts of the std::vector API, so it can replace std::vector
objects without needing an awkward adaptor class like Spanner.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell
2021-10-11 21:41:49 -04:00
parent 2e36dd2d58
commit f0eb9b202f
3 changed files with 207 additions and 0 deletions

View File

@ -4,6 +4,7 @@ default: libcrucible.a
%.a: Makefile
CRUCIBLE_OBJS = \
bytevector.o \
chatter.o \
city.o \
cleanup.o \