#Naming conventions: init, deinit, create, destroy, etc
1 messages · Page 1 of 1 (latest)
seems like: init and deinit generall operate on non-pointer values; create and destroy generally operate on pointers and allocate/free memory.
is that right? are there other related rules & conventions?
that about sums it up. You also often see initWith<Something>, where <Something> is something like Allocator, Capacity - that sort of thing
Or sometimes a type doesn't need a constructor, because it can be default-initialised (like std.ArrayListUnmanaged can be f.e.)
that's also a convention often seen in the stdlib, and sometimes userland code/libraries: <T>Managed vs <T>Unmanaged
it usually refers to whether or not a data structure carries around its allocator or not
gotcha. thanks. seems like the "default" convention is "unmanaged"? ie, for both create & destroy accept a matching allocator as params?
which is what i'd expect to avoid the extra pointer(s) stored everywhere
Well, it depends
the rule of thumb is: if you're storying it as a variable, Managed is fine, because it's probably going to be used often
if it's stored in-memory (e.g. an arraylist of arraylist), then you're better of using an unmanaged version, so you can share a single allocator value among many unmanaged data structures in-memory
(and also to save space on the 16 extra bytes per item)