Hello,
Currently I am learning ZIG-Langue, I have a project that I use for that.
I was helped a lot to understand packaging with const xxx struct …
My question :
I made structures which include for each model all its functions which it needs, until there, there is no problem.
But I also included an “arraylist” type data structure,
when I read the documentation, I see that we can do create with Allocator and consequently destroy or free.
https://ziglang.org/learn/overview/#manual-memory-management
I only did “clearandfree” everything works.
But wouldn’t it make more sense to take my data structure out of my general structure and use an init(create)remove(free) function
all this to get to clean all the data in progress during a module exit and return to the general module.
Or maybe do a create of my module for example
pub const pnl = struct {
....
/// define PANEL
pub const PANEL = struct {
name: [] const u8,
posx: usize,
posy: usize,
lines: usize,
cols: usize,
attribut: dds.ZONATRB,
frame: frm.FRAME ,
label: std.ArrayList(lbl.LABEL),
button: std.ArrayList(btn.BUTTON),
menu: std.ArrayList(mnu.MENU),
grid: std.ArrayList(grd.GRID),
field: std.ArrayList(fld.FIELD),
linev: std.ArrayList(lnv.LINE),
lineh: std.ArrayList(lnh.LINE),
// double buffer screen
buf:std.ArrayList(TERMINAL_CHAR),
idxfld: usize,
key : kbd , // Func task
keyField : kbd , // enter up down
actif: bool
};
.... function
}
I hope I’m not too stuffy, basically I’m trying to make good code for memory management and currently I’m not satisfied on this part.