in reply to Bit vector fiddling with Inline C

Is the data very large or is there some kind of external DMA interface requirement? Or where exactly is Perl not delivering in this particular case?

One world, one people

Replies are listed 'Best First'.
Re^2: Bit vector fiddling with Inline C
by oxone (Friar) on May 09, 2011 at 09:50 UTC
    It just comes down to speed. The real case applies some fairly complex logic to multiple large bit vectors (each 1m+ bits) which runs a lot faster in C. What I have works well, but as noted in the OP I'm unsure if my approach is risky vs Perl's internals.
      OK now we know a bit more, here are a couple of thoughts - repeatedly manipulating such data in Perl even for interfacing will be slow. There are C macros (see perlguts) for managing data declared in Perl and passed by reference (C-style, not Perl-style). But I'd aim to get it into C static storage (scope it just outside your C routines) asap and leave it there (call C routines from Perl at every point it needs using in any way), preferably loading it directly into C in the first place and avoid reallocating C memory repeatedly i.e. when completely done with one 1Mb chunk, reuse the same static storage for successive such chunks to process. Don't use the SV char* type -- use e.g. static int fred*250000 (update: unsigned) (scoped before the C routines are declared but after __C__) for your C storage to avoid ASCII-zero truncation by libc whenever a null byte is encountered.

      One world, one people