Transparent packed C arrays
Transparent packed C arrays
am 21.11.2005 01:30:29 von Ilya Zakharevich
I was under impression that there was a Perl module which allowed
"transparent" (via overloading) access to vectors represented as C
arrays, e.g., to
$array = pack('L*',@vec);
so that r/w access, arithmetic operations etc. work without explicit
unpack()ing. However, I could not find it quickly via CPAN search.
Any hints?
Thanks,
Ilya
Re: Transparent packed C arrays
am 21.11.2005 02:32:20 von g_m
"Ilya Zakharevich" > wrote ...
>I was under impression that there was a Perl module which allowed
> "transparent" (via overloading) access to vectors represented as C
> arrays, e.g., to
>
> $array = pack('L*',@vec);
>
> so that r/w access, arithmetic operations etc. work without explicit
> unpack()ing. However, I could not find it quickly via CPAN search.
>
> Any hints?
>
> Thanks,
> Ilya
(useless semantic point:
a "hint" is a little prod towards the light from someone who already knows the answer.
In this case, it isn't me. )
Just a couple of comments:
--if you mean "bit-vectors", then it's not a module, it's just the 3rd member
of the "low-level string conversions", - "pack()", - "unpack()", ---and "vec()".
Other than that, on windows at least, there's the "Win32::API::Struct",
imported automatically by "Win32::API".
I don't know anything about it yet, so i can't say if it's what you want,
-but the top of its "DESCRIPTION" sounds promising: ....
[quoting from that: ....]
--------------------------------------------
Win32::API::Struct->typedef( NAME, TYPE, MEMBER, TYPE, MEMBER, ...)
This method defines a structure named NAME.
The definition consists of types and member names, just like in C.
In fact, most of the times you can cut the C definition for a structure
and paste it verbatim to your script, enclosing it in a qw() block.
The function takes care of removing the semicolon after the member name.
The synopsis example could be written like this:
Win32::API::Struct->typedef('POINT', 'LONG', 'x', 'LONG', 'y');
But it could also be written like this (note the indirect object syntax), which is pretty cool:
typedef Win32::API::Struct POINT =>
qw{
LONG x;
LONG y;
};
Also note that typedef automatically defines an 'LPNAME' type,
which holds a pointer to your structure. In the example above, 'LPPOINT'
is also defined and can be used in a call to a Win32::API
(in fact, this is what you're really going to use when doing API calls).
.....etc
------------------------------------------
~greg
Re: Transparent packed C arrays
am 21.11.2005 03:26:12 von g_m
Inline::Struct
"Ilya Zakharevich" wrote in message news:dlr4f5$2vn$1@agate.berkeley.edu...
>I was under impression that there was a Perl module which allowed
> "transparent" (via overloading) access to vectors represented as C
> arrays, e.g., to
>
> $array = pack('L*',@vec);
>
> so that r/w access, arithmetic operations etc. work without explicit
> unpack()ing. However, I could not find it quickly via CPAN search.
>
> Any hints?
>
> Thanks,
> Ilya
Re: Transparent packed C arrays
am 22.11.2005 00:00:18 von Ilya Zakharevich
[A complimentary Cc of this posting was sent to
~greg
], who wrote in article :
> Inline::Struct
I read the docs, but I see no advantage of Inline::Struct over
$value = unpack 'x[L170]L', $array;
substr $array, 170*4, 4, $value * 5;
I need something more Perlish, like
my $obj = ToPerl 'L*', pack 'L*', @vec;
print $obj->[170];
$obj *= 5;
$obj = $obj + $obj * $obj;
Etc.
> >I was under impression that there was a Perl module which allowed
> > "transparent" (via overloading) access to vectors represented as C
> > arrays, e.g., to
> >
> > $array = pack('L*',@vec);
> >
> > so that r/w access, arithmetic operations etc. work without explicit
> > unpack()ing. However, I could not find it quickly via CPAN search.
Ilya
Re: Transparent packed C arrays
am 22.11.2005 06:03:51 von g_m
PDL
(Perl Data Language)
----
"Ilya Zakharevich" wrote in message news:dltji2$pp8$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> ~greg
> ], who wrote in article :
>
>> Inline::Struct
>
> I read the docs, but I see no advantage of Inline::Struct over
>
> $value = unpack 'x[L170]L', $array;
> substr $array, 170*4, 4, $value * 5;
>
> I need something more Perlish, like
>
> my $obj = ToPerl 'L*', pack 'L*', @vec;
> print $obj->[170];
> $obj *= 5;
>
> $obj = $obj + $obj * $obj;
>
> Etc.
>
>> >I was under impression that there was a Perl module which allowed
>> > "transparent" (via overloading) access to vectors represented as C
>> > arrays, e.g., to
>> >
>> > $array = pack('L*',@vec);
>> >
>> > so that r/w access, arithmetic operations etc. work without explicit
>> > unpack()ing. However, I could not find it quickly via CPAN search.
>
> Ilya
>
Re: Transparent packed C arrays
am 22.11.2005 06:53:35 von tassilo.von.parseval
Also sprach Ilya Zakharevich:
> [A complimentary Cc of this posting was sent to
> ~greg
>], who wrote in article :
>
>> Inline::Struct
>
> I read the docs, but I see no advantage of Inline::Struct over
>
> $value = unpack 'x[L170]L', $array;
> substr $array, 170*4, 4, $value * 5;
>
> I need something more Perlish, like
>
> my $obj = ToPerl 'L*', pack 'L*', @vec;
> print $obj->[170];
> $obj *= 5;
>
> $obj = $obj + $obj * $obj;
Is it perhaps Convert::Binary::C that you were looking for?
I'm wildly guessing here but this module is so good that a
recommendation is always in order. I don't think it has that kind of
overloading you asked for but it's easy to write your own wrapper module
with the help of C::B::C.
Tassilo
--
use bigint;
$n=714233503437702801613970263303373711390544118542200534375 65440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
Re: Transparent packed C arrays
am 23.11.2005 03:17:25 von Ilya Zakharevich
[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
], who wrote in article <3ufq31F10ag49U1@news.dfncis.de>:
> > I need something more Perlish, like
> >
> > my $obj = ToPerl 'L*', pack 'L*', @vec;
> > print $obj->[170];
> > $obj *= 5;
> >
> > $obj = $obj + $obj * $obj;
>
> Is it perhaps Convert::Binary::C that you were looking for?
Convert::Binary::C is a preprocessor and parser for C type definitions.
??? What could be a relation?
> I don't think it has that kind of
> overloading you asked for but it's easy to write your own wrapper module
> with the help of C::B::C.
The module should define (several?) hundred functions. Never a simple
job to start from scratch.
BTW, in my examples above I want something like pack('L!*'), not
pack('L*') - so that native arithmetic can be used for overloaded
operations.
Thanks,
Ilya
Re: Transparent packed C arrays
am 23.11.2005 03:25:18 von Ilya Zakharevich
[A complimentary Cc of this posting was sent to
~greg
], who wrote in article <2dydnRZWq4IrOx_enZ2dnUVZ_v6dnZ2d@comcast.com>:
>
> PDL
> (Perl Data Language)
PDL is a 2M download. It is a very complicated module, with low
probability of being compilable out-of-the-box (e.g., it won't compile
here). How many hours it makes to compile it?
I'm looking for a simple reliable solution that other modules can rely
on.
Thanks,
Ilya