To merge two arrays youâll want to use something like appendSlice.
list1.appendSlice(list2.items);
Note that pointers to items in the slice should be considred invalid after this operation as it may require memory to be moved, in order to grow the backing slice.
or if anybody can help me on how to convert ArrayListUnmanaged to u8
If you are done growing/resizing the ArrayList, you can always call toOwnedSlice which gives you a slice over the data in the ArrayList.
â\nâ is a single byte âcharacterâ, which is why you canât append it using the appendSlice. You can just use append which is the method to append 1 item to an array list.
You are calling defer _ = gpa.deinit(); in your editorOpen function, but later in that function you are are making allocations with the gpa allocator that arenât freed and seem like they should persist beyond the scope of the function. The gpa.deinit() call checks for memory leaks and frees all of the allocations.
from the editorRefreshScreen function to the beginning of main, all other functions that need an allocator need to take allocator as a std.mem.Allocator parameter.
You shouldnât create separate allocator instances all over the place, normally you create the gpa in main and then pass the allocator-interface to functions that need it, then some parts of the program may use it to create a different allocator, that is just needed temporarily.
If you create separate allocators without having a good reason for it, it defeats the debugging features of the gpa, by not being sure anymore if your allocator was even de-initialized at all. By just using one, that is de-initialized in main, you can be sure it detects the leaks once the program shuts down, it also makes it easier to change what allocator is used if you eventually want to change it.
As @IntegratedQuantum has already pointed out it would be simpler to readFileAlloc the entire file, and then find the lines within that.
Additionally you donât need to concatenate all the lines before outputting them,
instead you can define a buffered writer and directly write the lines to it,
then flush the buffered writer to make sure everything is written.
Without a buffered writer you risk making more system calls (which your code avoids by concatenating first, but that itself creates unnecessary reallocations, when the goal is to output the result, writing the lines to a buffered writer is more efficient, because it means your program doesnât have to allocate and re-allocate a growing buffer)
(So something more like this String formatting in a bit more complex cases - #10 by plano)