//
// See core/container/array.onyx for an example.
//
- __make_overload :: #match {
- //
- // This is the fallback option for make. It simply allocates a zero-intialized
- // element of type T.
- #order 1000 (_: &$T, allocator := context.allocator) -> &T {
- memory :: package core.memory
-
- res := cast(&T) raw_alloc(allocator, sizeof T);
- memory.set(res, 0, sizeof T);
- return res;
- },
- }
+ __make_overload :: #match {}
- delete :: #match {
- #order 1000 macro (x: &$T, allocator := context.allocator) {
- if x != null do raw_free(allocator, x);
- }
- }
+ delete :: #match {}
}
current: u32;
}
- c := make(Context(T), allocator=context.temp_allocator);
+ c := new_temp(Context(T));
c.arr = x;
- c.current = 0;
next :: (use _: &Context($T), $access: Code) => {
if current < arr.count {
close :: (use c: &Context($T)) {
sync.mutex_destroy(&c.mutex);
- delete(c);
+ cfree(c);
}
// This iterator's context is allocated from the heap because
node_stack << .{ "start", 0, false };
children_of :: (edges: &$T, name: str) -> Iterator(str) {
- name_copy := make_temp(str);
+ name_copy := new_temp(str);
*name_copy = name;
return iter.concat(
allocator: Allocator;
make :: () => {
- return make(SnailNum, SnailNum.allocator);
+ return new(SnailNum, SnailNum.allocator);
}
make_pair :: (left, right: u32) => {
use core
use core.encoding {utf8}
+#inject runtime.vars.Enable_Heap_Debug :: true
+
main :: () {
- output: dyn_str;
+ output := make(dyn_str);
+ defer delete(&output);
+
for i: 0x1F0A0 .. 0x1F0E0 {
utf8.append_rune(&output, i);
}