]> gitweb.factorcode.org Git - factor.git/blob - vm/byte_arrays.hpp
GC maps for more compact inline GC checks
[factor.git] / vm / byte_arrays.hpp
1 namespace factor
2 {
3
4 struct growable_byte_array {
5         cell count;
6         data_root<byte_array> elements;
7
8         explicit growable_byte_array(factor_vm *parent,cell capacity = 40) : count(0), elements(parent->allot_byte_array(capacity),parent) { }
9
10         void grow_bytes(cell len);
11         void append_bytes(void *elts, cell len);
12         void append_byte_array(cell elts);
13
14         void trim();
15 };
16
17 template<typename Type> byte_array *factor_vm::byte_array_from_value(Type *value)
18 {
19         byte_array *data = allot_uninitialized_array<byte_array>(sizeof(Type));
20         memcpy(data->data<char>(),value,sizeof(Type));
21         return data;
22 }
23
24 VM_C_API cell allot_byte_array(cell size, factor_vm *parent);
25
26 }