Lastic local variable

J

Joey Sabey

Would it be possible to declare an instance of a class locally in a
function, and then have that stay there and be able to be accessed
later by a pointer to it (from another program)?
I am working on a DLL, and I need similar behaviour to this...
 
V

Victor Bazarov

Joey said:
Would it be possible to declare an instance of a class locally in a
function, and then have that stay there and be able to be accessed
later by a pointer to it (from another program)?
I am working on a DLL, and I need similar behaviour to this...

No. Local instances get destroyed (and their storage usually reused
for something else) after the function in which they appear returns
control to the caller, UNLESS they are static. Objects declared
'static' have the lifetime beyond the scope in which they are defined
and you can access them from outside (given you have the address).

That said, don't get your hopes up. Accessing the object though its
address from another program depends on the operating system in which
your programs are running. If the OS supports virtual memory for
processes, you'll have to jump through lots of hoops (probably not
worth your time) to access one process' memory from entirely different
process. That's a topic for a discussion in the newsgroup dedicated
to your OS.

V
 
J

Joey Sabey

Victor said:
No. Local instances get destroyed (and their storage usually reused
for something else) after the function in which they appear returns
control to the caller, UNLESS they are static. Objects declared
'static' have the lifetime beyond the scope in which they are defined
and you can access them from outside (given you have the address).

That said, don't get your hopes up. Accessing the object though its
address from another program depends on the operating system in which
your programs are running. If the OS supports virtual memory for
processes, you'll have to jump through lots of hoops (probably not
worth your time) to access one process' memory from entirely different
process. That's a topic for a discussion in the newsgroup dedicated
to your OS.

Ah. Not good... What I basically need to do is allow access to a class
to another language that isn't compatible with the class. I thought it
might be possible to declare an instance of the class within the DLL,
and pass the pointer out...
Any ideas how I might make this work?
 
J

Jim Langston

Joey Sabey said:
Ah. Not good... What I basically need to do is allow access to a class
to another language that isn't compatible with the class. I thought it
might be possible to declare an instance of the class within the DLL,
and pass the pointer out...
Any ideas how I might make this work?

What is the other language and platform? I understand that C can access C++
structures, but only as C structructures.

Also, you minght want to look up "shared memory" in your OS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top