Solved

Direct memory manipulation from perl

Posted on 2004-04-12
4
256 Views
Last Modified: 2010-05-18
We have a runtime databank of addresses that are currently accessed with c-programs.  I am hoping to gain the functionality of PERL in several portions of the project that are not time-critical.   Is it possible to have perl directly read and edit this memory bank similarly to what c does?  

For example, I would need to be able to pass a perl script a list of addresses, and then have the script read the existing data from the RAM.  Also, if new variables were created, they would have to be then placed in specific/ newly dedicated locations.  (There is aof course a memeory tracking scheme already in place...)

One might suggest "simply" embedding perl into C, and have C handle the addressing, but I was hoping for a more direct route.  For some reason I can successfullly embed perl in Windows and in several Unix system (inc. Linux), but have been unsuccessful on Onyx (SGI) and Cygwin - the examples in perlembed are unresponsive.
0
Comment
Question by:str8dn
  • 3
4 Comments
 
LVL 1

Author Comment

by:str8dn
ID: 10810559
A further example will probably help...

Say I use C code to create a variable called var1:

double *var1
var1 = (double) malloc (2000);

If I know the address in RAM where the 2000 bit value for val1 is stored, is there a way to acces the data via a PERL script?
Reading var1 with a c-program, and then passing the values is an option, but I was hoping to find a more elegant solution...

Thanks,

str8dn
0
 
LVL 20

Accepted Solution

by:
jmcg earned 500 total points
ID: 10810696
You might consider whether the capabilities of the Sys::Mmap module will do what you need. In particular, see the 'hardwire' method. Even if the module cannot be used as-is, you could mine it for applicable ideas.

http://search.cpan.org/~swalters/Sys-Mmap-0.13/

Also, for some more ideas, see

http://search.cpan.org/~robm/Cache-FastMmap-1.05/

There are a lot of cautions and caveats that apply to using these methods, since Perl usually has a much more "managed" access to data than traditional C.
0
 
LVL 1

Author Comment

by:str8dn
ID: 10819752
I will take a look, thanks.

str8dn
0
 
LVL 1

Author Comment

by:str8dn
ID: 10920640
Thanks for the info.  After looking over it I have decided another, less intensive route, will give me closer to what I really want, with protability to boot.

Thanks again,

str8dn
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question