Now the newest version is in topling-ark
Core utilities of nark library
- boost-1.41 or newer
nark-bone
use boost as header-only library
$ cd /path/to/nark-bone
$ make
valvec support nark-serialization.
valvec
is much faster than std::vector
when expanding memory, when expanding,
std::vector
first allocate a larger memory, then copy-cons(move-cons in c++11) old
objects, this is slow. But valvec
just calling `realloc' to expand the memory, in
virtual addressing system, for example:
void* p = malloc(oldsize); // `p` is a virtual address
/// do something
void* q = realloc(p, newsize); // `q` is another virtual address
When available virtual address range pointed by p
is not big enough,
it is posible to just remap the physical address of p
into a larger
free virtual address range. Most popular malloc
implementations have used remap
to get this advantage.
- risk_set_data, risk_set_size, risk_set_capacity
- risk_release_ownership
nark-fsa use these functions for supporting DFA memory map in an graceful way.
nark::valvec<int> vec;
vec.push(1); // `push` is an alias of `push_back`
vec.push(2); // expand when full
//...
vec.reserve(vec.size() + 100);
vec.unchecked_push(123); // assert when full
int val = vec.pop_val(); // throws when empty
//...
while (!vec.empty()) {
int top = vec.unchecked_pop_val();
//...
}
For example, gnu std::list,map,set
... are not memmove-able, because they
have self-references.
//... int i = nark::lcast("123"); long l = nark::lcase(std::string("1") + "23"); float f = nark::lcast("1.23"); double d = nark::lcast("1.23");
<h3 id="read-text-lines">Read text lines</h3>
```c++
#include <nark/util/linebuf.hpp>
//...
nark::LineBuf line;
nark::valvec<fstring> fields; // fstring didn't own memory
while (line.getline(stdin) > 0) {
line.chomp(); // like perl chomp
line.split(&fields);
if (fields.size()) {
double dval = nark::lcast(fields[0]);
//...
}
}