Repository navigation
Description
We want to provide a way to hand over buffers to tskit, so that we can avoid the overhead of having two copies of the same data.
In #2006 we discussed the idea of adding a TSK_TAKE_OWNERSHIP flag to the existing x_table_set_columns and x_table_set_metadata (etc) methods. However, this would require adding an options parameter and removing the const qualifiers from all the parameters. This would break peoples code, make the library less easy to analyse by compilers and static analysis tools, and wreak utter havoc on our test suite (unless we turned off lots of warnings).
As discussed here and in following comments, we decided it was simpler to add new methods, which would be the same as the existing x_set_y methods, but would take the buffer(s) instead of copying them.
We also considered renaming the current x_set_y methods to x_copy_y, to better convey their semantics. This would be an annoying and noisy change to library users, though.
On reflection, I suggest the following.
- We keep the current methods like
tsk_node_table_set_columnsandtsk_reference_sequence_set_data, documenting them as "set the properties of the object to copies of the specified values" - We add new methods like
tsk_node_table_takeset_columnsandtsk_reference_sequence_takeset_data, documenting them as "set the properties of the object to the specified values and take ownership of the buffers". These would (correctly) have non-const arguments.
I like this because it doesn't break any existing code. I prefer takeset to just take because it makes it a bit clearer that we're doing the equivalent of set except we're also taking control of the buffer. If we're being purists it should be take_set rather than takeset, but I like the compound because it emphasises that it's one action, and given that there's four underscores in the name above, it makes it a bit clearer. We could say "settake", but it doesn't roll off the tongue quite as easily for me.
I've done an initial pass on doing this for the reference sequence over in #2011
Any thoughts @benjeffery @bhaller @molpopgen ?
Activity
bhaller commentedon Dec 5, 2021
This all sounds good to me. Not sure about
takesetvs. justtake, but no real objection to it. :->benjeffery commentedon Dec 6, 2021
I like this, as I said elsewhere
takesetis great as it seems a bit odd and unfamiliar, which it should be as you can shoot yourself in the foot and will help to get people to read the docs to know what it is.