opensourcer has asked for the wisdom of the Perl Monks concerning the following question:

i have c++ application just like windows explorer and i have embedded perl into that application. when i run that application it displays the content of the directory/drive, so that data is pretty much available in memory. now i want to create a few perl scripts so that they can search the on data available in the memory ( please assume that i know/created some address for storing information from c++ app). if u could give a sample code based on this Q using simple string pointer of int pointer, i'll be very thankfull "Im not really on earth it's just my reflection"

Replies are listed 'Best First'.
Re: acessing pointer data from the memory
by BrowserUk (Patriarch) on Feb 01, 2005 at 10:13 UTC

    If, as seems clear to me from your question, the perl interpreter is embedded within the C++ process who's memory you are trying to access, then it it just a case of making your C++ memory be visible to the interpreter.

    The section of perlembed (which you have presumably have read?) entitled "Fiddling with the Perl stack from your C program" would appear to describe what you are looking for.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
Re: acessing pointer data from the memory
by jbrugger (Parson) on Feb 01, 2005 at 06:23 UTC
    The Advanced Perl Programming might help?<quote of the book>
    Perl supports both concepts, and quite well, too. It allows you to create anonygmous data structures, and supports a fundamental data type called a "reference," loosely equivalent to a C pointer.
    Just as C pointers can point to data as well as procedures, Perl's references can refer to conventional data types (scalars, arrays, and hashes) and other entities such as subroutines, typeglobs, and filehandles.
    Unlike C, they don't let you peek and poke at raw memory locations.
    ** Update ** shortened the quote a little.
Re: acessing pointer data from the memory
by borisz (Canon) on Feb 01, 2005 at 07:58 UTC
    Another process can not read or write to data of your process. read perlipc. Basicly your tasks can share a special memory area or they talk via pipes. This is not a limitation/feature of perl its your os.
    Boris
      Did you miss the part where he said his perl interpreter is embedded into his application? Thus, it's all the same process?

      --
      [ e d @ h a l l e y . c c ]

        No, I understand it that way, that he embed a perl interpreter, that may share with tghe cpp application. But also start scripts, external to the application. The scripts should share something with the cpp application where perl is embedded. Maybe I get it wrong.
        Boris
Re: acessing pointer data from the memory
by Anonymous Monk on Feb 01, 2005 at 15:44 UTC
    Basically, you'd need to write a piece of XS code (or Inline::CPP code that will be turned into XS for you) that takes the data found on the specific memory location, and turns that in the appropriate Perl datastructure. The Perl API has lots of helper functions to create Perl datastructures.
Re: acessing pointer data from the memory
by mkirank (Chaplain) on Feb 01, 2005 at 09:49 UTC
    Like someone had suggested perlipc is the way to go, Look at shared memory .
    Any reason why you do not create an Index of the directory/drive (update this frequently) and search from there ?