Replies: 4 comments 4 replies
-
Ben J. replied: Can you not ask tskit to resize the block (e.g tsk_individual_table_expand_metadata) then assign into it rather than doing it yourself? If you can't do that then as long as max_metadata_length is the length of the buffer and metadata_length the length of the buffer that is used for data then all is good. As long as max_metadata_length >= metadata_length it doesn't matter the exact value. And yes any _offset column is one bigger than max_rows. |
Beta Was this translation helpful? Give feedback.
-
Hmm, perhaps I can use tsk_individual_table_expand_metadata(). The new metadata depends on the old metadata, so I'd need to copy off the old data into a side malloced block, then call tsk_individual_table_expand_metadata() and fix it, I guess. But all of the offsets are changing too. Seemed easier to just munge things to be the way I want them to be, but I'll look further at tsk_individual_table_expand_metadata() etc. to make sure. As for the size of the offset column's malloced block, OK, good to know that I'm safe if I malloc a new one that has room for max_rows + 1. Is that rule written down anywhere, and the rule that the first offset value is always 0 (instead of the constant 0 value being missing, and the number of rows equalling max_rows, which would be the other obvious way to implement things)? Would be nice to have a few more comments in the header about how such things work, unless it's already there and I missed it. |
Beta Was this translation helpful? Give feedback.
-
You could also use the
We wouldn't ever document that in the text documentation as we don't want to make forward promises as to how internal things such as this work, I guess we could put something in the header, but I'd be against that as it just has the possibility of getting out of date. The code is quite clear on the how big tables are when they are allocated as it all happens in the
While that way might be simpler on the allocation side, it complicates usage as you can't just do |
Beta Was this translation helpful? Give feedback.
-
I'm with @benjeffery here - documenting this sort of low-level implementation detail would mean freezing the implementation forever. |
Beta Was this translation helpful? Give feedback.
-
Hi! Asked this to Ben J. on Slack, and he suggested I open a Discussion, so here I am. :->
Are the exact rules governing the internal allocation sizes of table columns in tskit spelled out somewhere? I am having to replace a table column in a node table with a new malloced block, because I’m having to rewrite all the metadata for the table in a certain situation, and the length (in bytes, not rows) is changing. I’m wondering what the safe/correct way to do that is. I’m having to set metadata_length and max_metadata_length, and I’m a bit nervous that if I don’t do things in exactly the way tskit expects, it will end up causing a crash in one way or another. I’m particularly unsure of the rules for the metadata_offset column, and what allocation size it is guaranteed to have, since I guess it always uses one slot more than num_rows; if there are 10 rows then there are 11 values in metadata_offset, as I understand it, the first of which is guaranteed to be zero. Does that mean that it is guaranteed to have one more slot allocated in it than max_rows? If max_rows is 10, then metadata_offset is guaranteed to have enough space allocated for 11 values? Or how exactly does that work? Anyhow, if you can point me towards guidance regarding the correct way to do this, I’d appreciate it. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions