First, I don't know how to do that in perl. Second, I've looked through CPAN and found nothing. Thus, I think, if you haven't played with XS programming, now should be good time to begin doing that :) I'd suggest writing a module that operates with filehandles that require aligned access, and deals with the aligned buffers internally in C. This approach will create slight memory copying overhead (and this is perl, so that impact must be negligible I guess), but will produce a nice and clean open/read/write/etc perl API, that can be added to the big family of IO:: modules, and/or used as a tied filehandle.

There's also a possibility to write a module that somehow manages to create SVs that refer internally to aligned memory, but that approach raises (for me) more questions than answers (should they be R/O or R/W? and if R/W, how perl should be told to re-allocate the memory correctly?). Apologies if I've muddied the waters more than necessary, but possibly some of these ideas can help you.


In reply to Re: sysread/syswrite and O_DIRECT alignment problem by dk
in thread sysread/syswrite and O_DIRECT alignment problem by fishnuts

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.