473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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...

Jan 18 '07 #1
3 1092
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
Jan 18 '07 #2

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?

Jan 18 '07 #3
"Joey Sabey" <Ga***********@googlemail.comwrote in message
news:11*********************@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.
Jan 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jonathan | last post by:
I'm puzzled by Python's behavior when binding local variables which are introduced within exec() or execfile() statements. First, consider this simple Python program: # main.py def f() : x = 1...
2
by: Kench | last post by:
I was curious and playing with pointers and references to see what's different between them. Other than the obvious ones involving C++ syntax & things like references cannot be modified with...
9
by: Stefan Turalski \(stic\) | last post by:
Hi, I done sth like this: for(int i=0; i<10; i++) {...} and after this local declaration of i variable I try to inicialize int i=0;
5
by: FireHead | last post by:
Hello All, Its hard to explain but here it goes: char &free_malloc(char* object_copy){ Here ------------------------------------------------------------------ object_copy is parametre were...
14
by: Spitfire | last post by:
Hi All, I've this weird question about pointers. I would like to know how to return the address of a local variable, safely!! Isn't that a unrecommended procedure? Doesn't it have possibilities...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
25
by: guisep4 | last post by:
I have unusual "problem" with naming local variable "index". It all began when I added -Wshadow to gcc commandline. The code is like this: #include <string.h> int foo(void) { int index; ...
7
by: pauldepstein | last post by:
#include <iostream> using namespace std; double & GetWeeklyHours() { double h = 46.50; double &hours = h; return hours; }...
2
by: Matt Nordhoff | last post by:
Sebastjan Trepca wrote: Python doesn't like when you read a variable that exists in an outer scope, then try to assign to it in this scope. (When you do "a = b", "b" is processed first. In...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.