• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

How to handle SCALAR memory address pointer?

Is the following supported by PERL?

$address = MEMORY_ADDRESS_AS_VALUE; # i.e.: "145489952" is the address scalar value

# now we treat $address as an array reference:
$address[0] = ...
$address[1] = ...
$address[2] = ...
etc.

Basically, if I know the ACTUAL PHYSICAL ADDRESS, as a scalar value, how can I use it to access an array that begins at that address?

I know that C can handle such a thing. In C, just set the pointer to a memory address and use it to reference starting at that address.

THanks!

sapbucket
0
sapbucket
Asked:
sapbucket
  • 5
  • 4
  • 2
  • +1
1 Solution
 
sapbucketAuthor Commented:
or, put succinctly:

how to access a known memory location, represented as a scalar value, using PERL?
0
 
roee_fCommented:
What a mess...

a. even at C you almost never know the "ACTUAL PHYSICAL ADDRESS" of a variable. You know the logical address of it, in the process virtual memory space.

b. the (wrong) equation "pointer=array" comes totally from c (in its roots in assmbly). To the best of my knowledge, in perl you can have no guarantee that members of an array will be in continuous memory. Even if so, the similiar syntax between pointers and arrays in C is just not there in Perl.

c. If I understand correctly, and this array/pointer comes from C function, and no one touches this array/pointer from when it's returned to your reading/writing it MAY be possible to manipulate it, by jumping the reference with sizeof(array_element). But, it is possible that your writing (from perl) will overwrite more than you know and want.
0
 
ozoCommented:
You might be able to
  use PeekPoke qw(peek);
  my $val = peek($address);
But what are you actually trying to accomplish?
Perhaps there is a better way to achieve your goals
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sapbucketAuthor Commented:
ozo,

  I have been trying to use an ActiveX control that provides methods and properties for a firewire camera that I purchased at www.imagingcontrol.com.

  I am using the camera for pattern recognition in an assembly line-like process.

  The activeX control manages an imageBuffer in RAM. I lose all performance capabilities if I have to write all images to file as .bmp, etc. So I am trying to use the ptr to the imagebufffer and do direct image processing in the system RAM.

  Through the functionality of the ActiveX control I can access the image buffer, perform image processing tasks, and save the buffer. However, this being an Microsoft OLE ActiveX control, it was designed specifically for VB6. Using any other language is a "work around."

  I have never learned VB6, and I have already written an image processing library in PERL. I could use Java, but I encounter the same problem of not being able to access the ActiveX control.

  In actuality, all my problems would go away if i wrote my whole application in VB :)

  But for me to switch I will have to learn a whole new IDE, language, mode of thinking, etc.

 
  You are right. There must be a better way to achieve my goals.



All of the following questions are related to this one: (all 500 points)
http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21223912.html
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21221422.html
http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21220762.html
 
0
 
roee_fCommented:
If this activex has an OLE interface, you may be able to work through Win32::OLE.
I've had good and bad experience with some types of OLEs. So your mileage may vary.

Activestate has an OLE-browser, similiar to the one that MS has in VB. I would try to look there for the relevant functions.
0
 
ozoCommented:
If the camera API has no other appropriate methods, PeekPoke, or a similar C xs may be your only viable option in Perl.
0
 
sapbucketAuthor Commented:
OK,

   This is so simple in C.

   Can PERL do the following? (c-code example)

<START EXAMPLE>
   byte *pointer = ImageDataPtr();      # ImageDataPtr returns long (the location of the first byte)
   &pointer = 255 - &pointer;      // Change the content of the byte
   pointer++; // get the next byte
<END EXAMPLE>


ozo, I thought maybe using Inline C would work because I could embed the C functionality in a PERL script. (http://www.experts-exchange.com/Programming/Q_21201452.html). You think that would work? I'm not sure how to expose the function ImageDataPtr() using C, but I can with PERL: so, I will need to pass a value to the inline C. I read somewhere that this is possible...I'll look into it.

PERL doesn't seem to provide built-in functionality for handling pointers.

At my skill level I didn't realize that there is a difference between a PERL REFERENCE and a C POINTER. Not the same at all.


Thanks for any suggestions everyone. If you can impliment the 3-line C-example in this post using PERL I will be most happy.

0
 
ozoCommented:
use PeekPoke qw(peek poke);
$pointer = ImageDataPtr();
poke($pointer,255-peek($pointer));
$pointer++;


use Inline C;
C(ImageDataPtr());
__END__
__C__
int C(byte *pointer){
   *pointer = 255 - *pointer;
   pointer++;
}
0
 
sapbucketAuthor Commented:
ozo,

  byte* is not supported by lib/ExtUtils/typemap. Nor is long*.
 
  Unfortunately, long, is what I have for a return value from ImageDataPtr(). And long * is supported so I have to convert. So instead I pass in as char * and use atol() to convert to long. From there I use a type cast conversion into an unsigned char* (basically a byte) and can "see" the byte using printf.


TO ANSWER THIS:
you must look in your perl distribution directory under lib/ExtUtils/typemap to see if you are using supported types. Then it is not at all easy to proceed...

How to proceed AFTER that is here:
http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21238875.html

 
I'm not sure if we should continue this question - there really isn't a good answer by anyone. Any arguments?
0
 
ozoCommented:
Is it ok if the C function calls ImageDataPtr() instead of it being passed from perl?
0
 
sapbucketAuthor Commented:
This problem has been solved,

   thanks for the help! Unfortunately none of the comments here satisfy the objective of the question.

   If there are no arguments I am going to close this question.
0
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now