Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Lastic local variable (http://www.velocityreviews.com/forums/t459904-lastic-local-variable.html)

Joey Sabey 01-18-2007 09:54 PM

Lastic local variable
 
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...


Victor Bazarov 01-18-2007 10:11 PM

Re: Lastic local variable
 
Joey Sabey wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask



Joey Sabey 01-18-2007 10:15 PM

Re: Lastic local variable
 

Victor Bazarov wrote:
> 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?


Jim Langston 01-19-2007 03:55 AM

Re: Lastic local variable
 
"Joey Sabey" <GameFreak7744@googlemail.com> wrote in message
news:1169158549.333340.76320@a75g2000cwd.googlegro ups.com...
>
> Victor Bazarov wrote:
>> 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?


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.




All times are GMT. The time now is 12:22 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.