MAT_VARGETSTRUCTS(3)

MAT_VARGETSTRUCTS πŸ’– (the Library Functions Manual girlies know)

okay bestie, come sit with me, we're doing a lil slice-and-dice on structure arrays and honestly? it's giving ✨precision✨. this is Mat_VarGetStructs(3), no cap.


🌸 NAME 🌸

Mat_VarGetStructs β€” index a structure variable using slices of each dimension πŸŽ€


✨ SYNOPSIS ✨

#include <matio.h>

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

(yes the cons is right there, we do not touch the signature, we respect the signature πŸ’…)


πŸ¦‹ DESCRIPTION πŸ¦‹

So Mat_VarGetStructs() picks out a subarray from a structure array called matvar. And every single element in that subarray? It's got all the fields of the structure. all of them. no field left behind 🫢

Here's how the indexing goes, lowkey the important part:

  • for each dimension, the index starts at the start element in the array (and 0 is the first element, obviously)
  • then it reads every stride values β€” 1 means every element, 2 means every other element, etc., you get the vibe
  • the total number of elements in the subarray is specified as edge

Then there's the copy_fields option, and this is the one that actually decides how much work happens. It says whether the fields of the original structure get copied for the new subarray.

okay so 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. not a copy. a share. besties sharing one hoodie energy πŸ™ˆ

And when that happens, the subarray gets marked with the conserve memory flag, which means "do NOT free these fields." They are not yours to free. They get free'd when the original structure is free'd, periodt. so if you go freeing them yourself you're gonna have a bad time, that's the whole point of the flag 😭


πŸ’œ RETURN VALUES πŸ’œ

A subarray of the original structure array πŸŽ‰ …or NULL if there's an error πŸ’€


🌈 SEE ALSO 🌈


mwah, that's the whole page, you ate it ⭐

k bye, this was the MAT_VARGETSTRUCTS(3) page from the Debian fam, dated November 20, 2023, and the source/version energy at the bottom is very much Debian, November 20, 2023, MAT_VARGETSTRUCTS(3) β€” slay, stay indexed, don't free what isn't yours πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from