MAT_VARGETSTRUCTSLINEAR(3)

MAT_VARGETSTRUCTSLINEAR πŸ’…

okay bestie, this is a library function from the matio manual (section 3, the library-functions one, iykyk). it's literally called Mat_VarGetStructsLinear and it does exactly one iconic thing: linearly indexing a structure variable. slay.


✨ SYNOPSIS ✨

#include <matio.h>

matvar_t *
Mat_VarGetStructsLinear(const matvar_t *matvar, int start, int stride,
    int edge, int copy_fields);

πŸ¦‹ DESCRIPTION πŸ¦‹

so Mat_VarGetStructsLinear() picks out a subarray from a structure array matvar. and like, every single element in that subarray carries all of the fields of the structure β€” no field left behind, periodt. πŸ’–

the indexing math is giving very much "skip counting at recess":

  • it starts at the start element in the array (0 is the first element, bc of course it is)
  • and then it reads every stride values β€” so 1 means every element, 2 means every other element, etc.
  • the total number of elements in the subarray is edge
⚠️ heads up: the original array must have at least start+(stride-1)*edge+1 elements. that's not a suggestion, that's the vibe check the function is gonna run on your array.

now the copy_fields option β€” this is the main character of the whole function tbh. it says whether the fields of the original structure get copied over for the new subarray.

  • if you set it to 0, the returned structure array's fields have the same pointer as the original array, and the data field of the subarray structure.
  • the subarray gets marked with the conserve memory flag, which is basically its little "do not touch" sticker β€” it means those fields should not be free'd by the subarray.
  • they get free'd when the original structure is free'd. the original is the parent, the subarray is just borrowing the fit. πŸŽ€

🌸 RETURN VALUES 🌸

a subarray of the original structure array! πŸŽ‰

or NULL if there's an error. πŸ™ˆ that's it, that's the whole range.


πŸ‘‘ SEE ALSO πŸ‘‘


okay so that's the whole page, no cap. this little gem is from the Debian build of the manpage, dated March 14, 2012 β€” yeah she's a 2012 baby and she's still serving. πŸ’…βœ¨ stay indexed, bestie. πŸ«ΆπŸ’–

πŸ“¦ where this page comes from