[TUHS] Future Languages
Richard Tobin
richard at inf.ed.ac.uk
Wed Sep 6 00:41:55 AEST 2017
> So we have some source (that you can have as well, Apache license)
> that handles not strings but vectors of strings (or structs or whatever).
>
> I need to write up how it works, it's sort of clever. It stores both
> the size of the vector (always a power of 2) in part of the bits of the
> first entry and the actual length in the other part. Because we can
> express powers of two in very little space we can support both values
> in a 32 bit unsigned with a max length of used space of around 134M.
I have something similar. It allocates space for two ints (number
allocated and used) at ((int *)array)[-1] and [-2].
Typical use is
LTVectorAndInit(char *, names);
while(...)
LTVectorPush(names, s);
for(i=0; i<LTVectorCount(names); i++)
... names[i] ...;
LTVectorFree(names);
-- Richard
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the TUHS
mailing list