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] = ...

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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sapbucketAuthor Commented:
or, put succinctly:

how to access a known memory location, represented as a scalar value, using PERL?
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.
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

sapbucketAuthor Commented:

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

  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)
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.
If the camera API has no other appropriate methods, PeekPoke, or a similar C xs may be your only viable option in Perl.
sapbucketAuthor Commented:

   This is so simple in C.

   Can PERL do the following? (c-code 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

ozo, I thought maybe using Inline C would work because I could embed the C functionality in a PERL script. ( 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.

use PeekPoke qw(peek poke);
$pointer = ImageDataPtr();

use Inline C;
int C(byte *pointer){
   *pointer = 255 - *pointer;
sapbucketAuthor Commented:

  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.

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:

I'm not sure if we should continue this question - there really isn't a good answer by anyone. Any arguments?
Is it ok if the C function calls ImageDataPtr() instead of it being passed from perl?
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.
PAQed with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.