two question about linked lists
do I understand correctly that linklist_readonly() disables all the thread-locking mechanisms for a given linked list?
btw, linklist_readonly doesn’t link… what I’m doing is to directly set the readonly field to 1 – or is there more to know about that?
2 – though this is one I shouldn’t ask ;)
I need to chain together two linked lists. I am sure about their threading context, so I can turn off thread-safety for them.
The most obvious thing to do would be chaining them "manually", by appropriately setting heads, tails, prevs and nexts, and finally setting the OBJ_FLAGS_DATA flag to the second list and deleting it.
So here’s the point:
how "forbidden" is to go mess with the actual fields of t_linklist and t_llelem? how likely are these basic things to change in the (near) future? it looks a bit overkill to append one by one all the elements of the second list to the first one, but I didn’t find an API function able to do what I need…
In general it is inadvisable to modify these structures directly. Do so at your own risk.
1. You can use object_method(list,gensym("readonly"),1). Yes, this removes threadsafe locking, even if you need to write to the list.
2. Completely not recommended, especially since there is no way to safely free the appended list. We can consider this a request for an API call of linklist_appendlist, and similar for insert, but there’s no estimate on when it would be introduced.
One idea for appending would be to call linklist_funall on the list to append, and in your callback function, simply call linklist_append on each object. Then call linklist_chuck on the appended list you wish to dispose without freeing the objects it contains. This will be safe and reasonably efficient. Hopefully it suits your needs.
thank you Joshua, I’ll follow your advice.
Just to point out that linklist_readonly() and hashtab_readonly() still appear not to be exported (SDK 5.1.7).
You can set the readonly flags for these using object method (both linklist and hashtab are proper t_objects).
object_method(x->my_linklist, gensym("readonly"), 1);
Thank you Tim – in fact, this is what I’ve done…
It was just to let you know !
Forums > Dev