Lastic local variable

Discussion in 'C++' started by Joey Sabey, Jan 18, 2007.

  1. Joey Sabey

    Joey Sabey Guest

    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...
     
    Joey Sabey, Jan 18, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jan 18, 2007
    #2
    1. Advertising

  3. Joey Sabey

    Joey Sabey Guest

    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?
     
    Joey Sabey, Jan 18, 2007
    #3
  4. Joey Sabey

    Jim Langston Guest

    "Joey Sabey" <> wrote in message
    news:...
    >
    > 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.
     
    Jim Langston, Jan 19, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Carey

    Instance Variable vs Local Variable

    Paul Carey, Dec 3, 2003, in forum: Java
    Replies:
    3
    Views:
    817
    Chris Uppal
    Dec 3, 2003
  2. Jerry
    Replies:
    5
    Views:
    32,930
    Roedy Green
    Aug 6, 2005
  3. Patrick Hoffmann
    Replies:
    3
    Views:
    2,850
    Christian Jan├čen
    Aug 8, 2003
  4. Kench
    Replies:
    2
    Views:
    5,420
    Victor Bazarov
    Jun 28, 2004
  5. Mohanasundaram
    Replies:
    44
    Views:
    1,083
    Keith Thompson
    Aug 24, 2004
Loading...

Share This Page