]> gitweb.factorcode.org Git - factor.git/blob - vm/byte_arrays.hpp
vm: clean up gc events, remove -verbosegc switch, fix compaction bug
[factor.git] / vm / byte_arrays.hpp
1 namespace factor
2 {
3
4 struct growable_byte_array {
5         cell count;
6         gc_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         return byte_array_from_values(value,1);
19 }
20
21 template<typename Type> byte_array *factor_vm::byte_array_from_values(Type *values, cell len)
22 {
23         cell size = sizeof(Type) * len;
24         byte_array *data = allot_uninitialized_array<byte_array>(size);
25         memcpy(data->data<char>(),values,size);
26         return data;
27 }
28
29 }