two question about linked lists

Jul 31, 2010 at 7:11am

two question about linked lists

Hi.

1-

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…

thank you!
aa

#51586
Jul 31, 2010 at 5:02pm

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.

#185050
Jul 31, 2010 at 5:10pm

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.

#185051
Jul 31, 2010 at 5:55pm

thank you Joshua, I’ll follow your advice.
best
aa

#185052
May 13, 2011 at 9:35am

Hi.

Just to point out that linklist_readonly() and hashtab_readonly() still appear not to be exported (SDK 5.1.7).

Cheers
aa

#185053
May 25, 2011 at 3:30pm

Hi Andrea,

You can set the readonly flags for these using object method (both linklist and hashtab are proper t_objects).

For example:

object_method(x->my_linklist, gensym("readonly"), 1);

Cheers,
Tim

#185054
May 25, 2011 at 5:31pm

Thank you Tim – in fact, this is what I’ve done…
It was just to let you know !
best
aa

#185055

You must be logged in to reply to this topic.