Problems? Is your data what you think it is? | |
PerlMonks |
Need for (XS) speedby spx2 (Deacon) |
on Mar 05, 2010 at 05:39 UTC ( [id://826865]=perlquestion: print w/replies, xml ) | Need Help?? |
spx2 has asked for the wisdom of the Perl Monks concerning the following question: Hi, If it's known that inside an AV* array all the elements are IVs, or all the elements are UVs , can I measure the sizeof(IV) and instead of using av_fetch use normal C addressing of arrays like *(array+index) ?If this is not possible, is there a way to just not use av_fetch, but instead use something else, for example suppose I have a SV* , I would like to make what I want of it, that is, I want to completely ignore Perl's data structure and just write in it as if it were an usual C array. Will "corrupting" a Perl data structure in this way lead to any problems? (I wasn't able to think of any, the most important would be the refcnt , but we won't tamper with that). Normally I wouldn't do this because I know some people thought out Perl's data structures and they should be used with the API they have written but I want to write something that will be blazing fast so I need to break some rules here, such as portability(not interested in writing portable code, just extremely fast one). I'm sure I'm not the first one to think of this as there are so many XS modules on CPAN and there's a big chance one of them is doing this(only problem is I don't know which one). Another idea would be to use av_fetch to first get all the pointers of the elements of an array(a AV*)and put them in a SV* array[](maybe not even this, maybe just the _SV_HEAD_UNION members of the SV structs, as I understand by reading this, that they are actually the ones containing the data) and use that array because addressing it would be faster than using av_fetch each time. This of course, all depends on many Perl implementation details. I'm seeking general XS tips for speeding up code. Also, this is not a premature decision/thought as my code is already written, now I need to optimize it. Thanks
Back to
Seekers of Perl Wisdom
|
|