]> gitweb.factorcode.org Git - factor.git/blob - vm/byte_arrays.hpp
2da036709f6cf46e8c21a65ffddb28f7d3852378
[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 append_bytes(void *elts, cell len);
11         void append_byte_array(cell elts);
12
13         void trim();
14 };
15
16 template<typename Type> byte_array *factor_vm::byte_array_from_value(Type *value)
17 {
18         byte_array *data = allot_uninitialized_array<byte_array>(sizeof(Type));
19         memcpy(data->data<char>(),value,sizeof(Type));
20         return data;
21 }
22
23 VM_C_API cell allot_byte_array(cell size, factor_vm *parent);
24
25 }