Thanks Liz, I tried passing $list as the C array of doubles to mlfDoubleMatrix() to create a mxArray, and it didn't like it. I tried using "d" instead of "L*" which didn't work either. Do you know if pack() can be used to create an "actual" C array of doubles?
Thanks...Brady -----Original Message----- From: Elizabeth Mattijsen [mailto:[EMAIL PROTECTED]] Sent: Monday, June 10, 2002 3:27 PM To: Neil Watkiss; bbcannon Cc: '[EMAIL PROTECTED]' Subject: Re: Instantiating arrays with Inline At 01:49 PM 6/10/02 -0700, Neil Watkiss wrote: >bbcannon [10/06/02 14:43 -0600]: > > That sounds like a great idea if you know a > > more efficient way of creating an array from this string > > reference than Neil showed with his for loop. > > I'm very new to C, can you show me how to do this? Please don't expect any C guruism from me: it's been at least 10 years since I did any serious C programming other than simple patches to an existing program... >It seems to me that either way you'll be iterating through thousands of >entries. You might save a bit of overhead not going through an AV*, but I >suggest trying it first. Before using a complicated solution, you might as >well see whether the simple one is good enough. You're already in C, which is >very fast. Otherwise you're going to be taking a Perl array, using join() to >get a string, then basically splitting it up again from C into a C array. It >strikes me that this solution might be _slower_, since you could avoid the >join() and the split() by just converting the Perl array into a C array >directly. Actually, I meant using the Perl -pack- function (perldoc -f pack). It allows you to create what basically is a C array structure from within Perl. I am not sure whether you would want to convert back and forth all the time: it's probably better to keep it in the C-struct all the time anyway and create simple C accessor functions. Or use substr() and unpack() on your packed array to get to specific elements. So, for example: my $list = pack( 'L*',(65,66,67,68,69) ); # create 5 x 4 byte array printf "%vd\n",$list; # show how they are stored per byte # do your inline stufff my $i = 3; # set element to fetch my $value = unpack( 'L',substr($list,$i*4,4) ); # obtain value print "Element $element has value $value\n"; # show result Liz
