Questions about Inline::C



Dear all,

I had to revert to C again. Since the thought of parsing all my files in C
was dreadful, I decided to use Inline::C to only do the job that was really
computationally intensive. Currently, my program seems to run quite well,
I am very happy with Inline::C, and a little coding in C made me bless
Larry again and again.

There are, however, few questions that remain open.

1. In the Inline::C cookbook, it says

> I would urge you to stay away from "malloc"ing your own buffer. Just
> use Perl's built in memory management. In other words, just create a
> new Perl string scalar. The function "newSVpv" does just that. And
> "newSVpvf" includes "sprintf" functionality.

Why? I mean, is there is any danger with malloc() from within Inline::C
that is not present in regular C programs, or is it because using malloc
is just generally tricky? I much prefer to do the allocation myself,
as I know exactly how large my matrix is and as I want to allocate the
whole matrix ( say, double 2000 x 2000 ) in one go myself. The reason is
that I fear that using perl guts for my calculations (accessing the
matrix, calculating values in it etc.) will be not much slower than a
simple C implementation. Maybe I am wrong, I haven't tested it.

Furthermore, I feel more comfortable using things that I know well, even
thought they might turn dangerous.

2. When using Inline_Stack to return a list to Perl code, I found that the
following throws a segfault:

Inline_Stack_Reset ;
Inline_Stack_Push( sv2_mortal( newSVpv( 'score' ) ) ) ;
Inline_Stack_Done ;

...while the following does not:

Inline_Stack_Reset ;
Inline_Stack_Push( sv2_mortal( newSVpv( "score" ) ) ) ;
Inline_Stack_Done ;

Should I be worried, or is it normal behaviour? (I tried to look up the
definition of Inline_Stack_Push, but I have trouble finding it).

Cheers,

January

--
.



Relevant Pages

  • Re: misunderstanding
    ... ALL programming languages that support floats. ... But SQLite, exactly like Perl, doesn't do this: ... calculations with them should be very ugly. ... I've seen that PHP does the following program twice as fast as perl: ...
    (perl.beginners)
  • Re: why the perl docs suck
    ... It stands to reason that perl ... > allocation-copy-free sitting on top of block memory fragmented ... FLAGS = ... The fact that an upgrade results in a fresh allocation instead of an ...
    (comp.lang.perl.misc)
  • Re: why the perl docs suck
    ... It stands to reason that perl ... >> allocation as a computation left to designers of the software that ... >The addresses in brackets shows that the block of memory where the ... >> to pointers as with scalars to be the machine word. ...
    (comp.lang.perl.misc)
  • RE: Zip Codes, Long/Lat and LAMP?
    ... Maybe these questions should be posted on more general Perl lists until ... Zip Codes, Long/Lat and LAMP? ... locations) then I can find the math myself to calculate distances, ... calculations and it's not one included in the standard CPAN supported ...
    (perl.dbi.users)
  • Re: memory allocation in perl
    ... There is no explicit memory ... >> allocation in perl (well, actually, you can treat a string as a chunk ... > I want to whether we have some sort of allocation method as we have in C ... In perl there are only two basic ways to allocate variables. ...
    (perl.beginners)