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