Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The first test works fine, the second one ends with "Out of memory" after a long, painful swap to disk

Actually now that I re-read the description of your problem I have to conclude it probably has nothing at all to do with Inline::C. The second test is comparing the results of the pure Perl sub to the results of the sub that invokes an external program. That external program is the C++ program whos source I provided in my example.

That program is not seen or touched by Inline::C. Inline::C doesn't know or care about it.

The C++ program has to be saved in its own C++ source file, compiled, and linked to a filename that makes sense for your operating system. In fact whether it's Win32 or Linux, there's no harm in having an .exe suffix in this simple test case. Just compile the C++ source into an executable named 'primes.exe', and put it wherever the script will be able to find it (or specify a fully qualified path within the Perl script's call to primes.exe).

Maybe you've already done all this. If you haven't, go ahead and do it now.

The next step in sleuthing what's going wrong would be to invoke primes.exe (the executable built from the C++ source I provided). Invoke it with some smallish integer, like primes.exe 100. Then try it as primes.exe 100000, and again as primes.exe 1000000.

If it runs properly in all those cases, there's no sane reason it shouldn't work from within your Perl script. If it doesn't run properly, perhaps you have a C++ compiler and library that lacks the Standard Template Library, which is a necessary component of the C++ program.

If all else fails, you ought to be able to just remove the 2nd test, and remove all mention of the external_cpp() sub within the Perl script (remove the function's declaration/definition, and its use within the cmpthese() benchmark). Then you'll only be comparing the Inline::C function with the pure Perl one; you're taking the C++ program out of the equation.

Hope this helps...


Dave


In reply to Re^2: Exploring Inline::C (Generating primes) by davido
in thread Exploring Inline::C (Generating primes) by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2014-07-24 02:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (156 votes), past polls