473,385 Members | 1,357 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,385 software developers and data experts.

Stack Frame Object Instances?

Can you retrieve a calling object's instance from the stack via
reflection? So far I've only been able to traverse the stack and get
to a Type of the calling routine (using StackFrame.GetMethod and then
interogating that MethodBase object). What I'm trying to do is to
interrogate a property on the calling object instance.

Any ideas? Is this doable?
Jul 19 '05 #1
2 2302
You need to get to the "this" argument of the calling function. This is not
really supported. That argument may not even be available. If it is not used
in the function beyond that point, the JIT-compiler would optimize it away
as it is not "alive".
"Mark Sisson" <ma**@corporatedigital.com> wrote in message
news:88**************************@posting.google.c om...
Can you retrieve a calling object's instance from the stack via
reflection? So far I've only been able to traverse the stack and get
to a Type of the calling routine (using StackFrame.GetMethod and then
interogating that MethodBase object). What I'm trying to do is to
interrogate a property on the calling object instance.

Any ideas? Is this doable?

Jul 19 '05 #2
Passing in the calling instance as a param isn't possible for me.
What I'm writing is a Trace Listener that writes to a database. I'm
trying to add more information to the database entry and a key piece
of information for me is the calling instance that generated the trace
message.

As a work around, I've modified my listener routine to interogated the
name of the current thread. Since all of the objects that will be
tracing are running in their own threads (this is a multi-threaded
processing engine) I can set the the name of the thread to give me a
clue as to what object I've got.

I WISH THERE WAS A BETTER WAY BECAUSE THIS MODEL WOULD NOT WORK IN ALL
SITUATIONS.
Jul 19 '05 #3

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

Similar topics

15
by: Andrew | last post by:
Last night I was reading about implementing my own stack. The example given pushes items on and off the stack at the start and end of each procedure (ie. in a std module). What's not so clear is...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
2
by: Mark Sisson | last post by:
Can you retrieve a calling object's instance from the stack via reflection? So far I've only been able to traverse the stack and get to a Type of the calling routine (using StackFrame.GetMethod...
2
by: Nick McCamy | last post by:
I have a question related to allocating on the stack. In this program below, are my following assumptions true? - variable a is allocated on the heap since it's static - variable b is...
7
by: benben | last post by:
How can I convert a stack to array? I have a Stack of System.Drawing.Point's and I would like to invoke Graphics.DrawCurve, which takes a Point array as parameter. I tried Stack.ToArray but it...
9
by: shine | last post by:
what is the difference between a heap and a stack?
24
by: arcticool | last post by:
I had an interview today and I got destroyed :( The question was why have a stack and a heap? I could answer all the practical stuff like value types live on the stack, enums are on the stack, as...
16
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area...
7
by: Dougan | last post by:
I've seen code that allocates an object on the stack and then saves a class reference to it. example: void ScribbleArea::resizeImage( const QSize &newSize) { QImage newImage( newSize, );...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.