6 byte_array
* factor_vm::allot_byte_array(cell size
) {
7 byte_array
* array
= allot_uninitialized_array
<byte_array
>(size
);
8 memset(array
+ 1, 0, size
);
13 void factor_vm::primitive_byte_array() {
14 cell size
= unbox_array_size();
15 ctx
->push(tag
<byte_array
>(allot_byte_array(size
)));
19 void factor_vm::primitive_uninitialized_byte_array() {
20 cell size
= unbox_array_size();
21 ctx
->push(tag
<byte_array
>(allot_uninitialized_array
<byte_array
>(size
)));
25 void factor_vm::primitive_resize_byte_array() {
26 data_root
<byte_array
> array(ctx
->pop(), this);
28 cell capacity
= unbox_array_size();
29 ctx
->push(tag
<byte_array
>(reallot_array(array
.untagged(), capacity
)));
33 void growable_byte_array::reallot_array(cell count
) {
34 byte_array
*ba_old
= elements
.untagged();
35 byte_array
*ba_new
= elements
.parent
->reallot_array(ba_old
, count
);
36 elements
.set_untagged(ba_new
);
40 void growable_byte_array::grow_bytes(cell len
) {
42 if (count
>= array_capacity(elements
.untagged())) {
43 reallot_array(2 * count
);
48 void growable_byte_array::append_bytes(void* elts
, cell len
) {
49 cell old_count
= count
;
51 memcpy(&elements
->data
<uint8_t>()[old_count
], elts
, len
);
55 void growable_byte_array::append_byte_array(cell byte_array_
) {
56 data_root
<byte_array
> byte_array(byte_array_
, elements
.parent
);
58 cell len
= array_capacity(byte_array
.untagged());
59 cell new_size
= count
+ len
;
60 if (new_size
>= array_capacity(elements
.untagged())) {
61 reallot_array(2 * new_size
);
64 memcpy(&elements
->data
<uint8_t>()[count
], byte_array
->data
<uint8_t>(), len
);
70 void growable_byte_array::trim() {