Skip to content

Commit d72a1e5

Browse files
committed
Reduce default heap size to 16MB. Start GC refactoring for ByteArray.
1 parent 1042cd3 commit d72a1e5

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Alloc
1515
{
1616
pub fn new() -> Self
1717
{
18-
Self::with_size(32 * 1024 * 1024)
18+
Self::with_size(16 * 1024 * 1024)
1919
}
2020

2121
pub fn with_size(mem_size_bytes: usize) -> Self

src/bytearray.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,16 @@ fn blit_bgra32(
169169
}
170170
}
171171

172-
/// Create a new ByteArray instance
173-
pub fn ba_new(actor: &mut Actor, _self: Value) -> Result<Value, String>
174-
{
175-
let ba = ByteArray::default();
176-
let new_arr = actor.alloc.alloc(ba).unwrap();
177-
Ok(Value::ByteArray(new_arr))
178-
}
179-
180172
/// Create a new ByteArray instance
181173
pub fn ba_with_size(actor: &mut Actor, _self: Value, num_bytes: Value) -> Result<Value, String>
182174
{
183175
let num_bytes = num_bytes.unwrap_usize();
176+
177+
actor.gc_check(
178+
size_of::<ByteArray>() + num_bytes,
179+
&mut []
180+
);
181+
184182
let mut bytes = Vec::with_capacity(num_bytes);
185183
bytes.resize(num_bytes, 0);
186184
let ba = ByteArray { bytes };

src/host.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ pub fn cmd_get_arg(actor: &mut Actor, idx: Value) -> Result<Value, String>
166166
return Ok(Value::Nil);
167167
}
168168

169-
Ok(actor.alloc.str_val(&args[idx]).unwrap())
169+
let arg_str = &args[idx];
170+
Ok(actor.alloc.str_val(arg_str).unwrap())
170171
}
171172

172173
/// Print a value to stdout

src/runtime.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ pub fn get_method(val: Value, method_name: &str) -> Value
365365
static ARRAY_INSERT: HostFn = HostFn { name: "insert", f: Fn3(array_insert) };
366366
static ARRAY_APPEND: HostFn = HostFn { name: "append", f: Fn2(array_append) };
367367

368-
static BA_NEW: HostFn = HostFn { name: "new", f: Fn1(ba_new) };
369368
static BA_WITH_SIZE: HostFn = HostFn { name: "with_size", f: Fn2(ba_with_size) };
370369
static BA_FILL_U32: HostFn = HostFn { name: "fill_u32", f: Fn4(ba_fill_u32) };
371370
static BA_READ_U32: HostFn = HostFn { name: "load_u32", f: Fn2(ba_load_u32) };
@@ -422,7 +421,6 @@ pub fn get_method(val: Value, method_name: &str) -> Value
422421
(Value::Array(_), "insert") => &ARRAY_INSERT,
423422
(Value::Array(_), "append") => &ARRAY_APPEND,
424423

425-
(Value::Class(BYTEARRAY_ID), "new") => &BA_NEW,
426424
(Value::Class(BYTEARRAY_ID), "with_size") => &BA_WITH_SIZE,
427425
(Value::ByteArray(_), "fill_u32") => &BA_FILL_U32,
428426
(Value::ByteArray(_), "load_u32") => &BA_READ_U32,

src/vm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ impl Actor
17921792
self.gc_check(
17931793
std::mem::size_of::<Object>() +
17941794
std::mem::size_of::<Value>() * num_slots,
1795-
&mut vec![],
1795+
&mut [],
17961796
);
17971797

17981798
let obj_val = self.alloc.new_object(class_id, num_slots).unwrap();
@@ -1828,7 +1828,7 @@ impl Actor
18281828
self.gc_check(
18291829
std::mem::size_of::<Object>() +
18301830
std::mem::size_of::<Value>() * num_slots,
1831-
&mut vec![],
1831+
&mut [],
18321832
);
18331833

18341834
// Allocate the object
@@ -1993,7 +1993,7 @@ impl Actor
19931993

19941994
self.gc_check(
19951995
size_of::<Array>() + size_of::<Value>() * capacity,
1996-
&mut vec![],
1996+
&mut [],
19971997
);
19981998

19991999
let new_arr = Array::with_capacity(capacity, &mut self.alloc).unwrap();
@@ -2755,7 +2755,7 @@ mod tests
27552755
#[test]
27562756
fn bytearray()
27572757
{
2758-
eval("let a = ByteArray.new();");
2758+
eval("let a = ByteArray.with_size(0);");
27592759
eval("let a = ByteArray.with_size(1024); assert(a.len == 1024);");
27602760
eval("let a = ByteArray.with_size(32); a.store_u32(0, 0xFF_FF_FF_FF);");
27612761
eval("let a = ByteArray.with_size(32); a.store_u32(0, 0xFF_00_00_00); assert(a[0] == 0 && a[3] == 255);");

0 commit comments

Comments
 (0)