Your skill will accomplish
what the force of many cannot
Re^3: Perl XS binding to a struct with an array of chars*by syphilis (Archbishop)
|on Nov 24, 2022 at 01:10 UTC ( #11148345=note: print w/replies, xml )||Need Help??|
Normally a type has a fixed size that is known at compile time and sizeof() works just fine. That is not true in this case.
Well, I think that the struct, as presented in the original post, does have a definite size (of 16 bytes).
AFAIK specifying char *str is equivalent to char * str.
I just went with the spec provided, even though it looked rather odd.
It did occur to me that the OP might have intended char ** string_array (as you've suggested), and I probably should have pressed MaxPerl about that.
But, either way, the struct has a definite size - and we can assign memory to it based on that size (which is 16 bytes, on my Windows 11 64-bit system).
I've no experience with structs that might require varying amounts of memory that can't be known until runtime. (I don't assume that such cases never arise.)
I expect that the OP's strings have been created separately.
Therefore, the number and size of them has no impact on the struct's memory allocation - because the struct just takes a pointer to the array of strings, no matter how large that array is.
In Section Seekers of Perl Wisdom