473,246 Members | 3,729 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,246 software developers and data experts.

How to find whether Object is in HEAP/Stack.

Hi Gurus
I need a help. Im developing a C++ libaray. I don't
whether user creates object in stack/heap. Is there a
way to find object location?

Balu.N

Aug 9 '05 #1
3 3105
balu wrote:
Hi Gurus
I need a help. Im developing a C++ libaray. I don't
whether user creates object in stack/heap. Is there a
way to find object location?

Balu.N


Why do you care?

Aug 9 '05 #2
balu wrote:
Hi Gurus
I need a help. Im developing a C++ libaray. I don't
whether user creates object in stack/heap. Is there a
way to find object location?

Balu.N


There is no facility in C++ itself to provide this information. There
are various ways a program can try to capture this information when the
object is allocated. But even this approach can be more difficult than
it looks. There are also non-portable ways of finding an object's
location, ususally involving pointer comparisons.

More often than not, though, there is a better question to ask than
this one. After all if a client can instantiate an object of a
particular class either on the heap or on the stack, then the class
should have little reason to care which location the client picked.

On the other hand, if the location does make a difference to the class,
it is often better for the class to allow allocation in only one type
of location. For instance, ref-counted objects almost always have to be
allocated on the heap. For a class of this type, allocating on the
stack would either make no sense or would require a behavior so
different from heap-based objects of the same class - that permitting
both would just be too confusing. In this case, it would be perfectly
appropriate for the class to enforce heap-based allocation, usually
through a factory method and a private constructor.

Without knowing more about the background of this question, I cannot
suggest what the better question might be. But I think it quite likely
that a better question does exist.

Greg

Aug 9 '05 #3
balu wrote:
Hi Gurus
I need a help. Im developing a C++ libaray. I don't
whether user creates object in stack/heap. Is there a
way to find object location?

Balu.N


Why do you care?

Aug 9 '05 #4

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

Similar topics

5
by: August1 | last post by:
This is a short program that I have written from a text that demonstrates a class object variable created on the stack memory and another class object variable created on the heap memory. By way...
11
by: Dan Elliott | last post by:
Hello all, I am writing a program which needs to run as quickly as possible, but holds a lot of data in memory (around 1GB for a usual run). Is this too much memory to even consider putting...
13
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I...
1
by: Geiregat Jonas | last post by:
I'm reading Eric Gunnerson's book. He is talking about the heap and stack, he says you have 2types, value wich are in the stack or inline or reference types wich are in the heap. I don't get...
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...
3
by: nahur | last post by:
why do you need a heap and a stack why not all memory called a heap or call it a stack what is the purpose of having a heap and a stack
7
by: Arpan | last post by:
The .NET Framework 2.0 documentation states that An Object variable always holds a pointer to the data, never the data itself. Now w.r.t. the following ASP.NET code snippet, can someone please...
53
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global...
1
by: mattmao | last post by:
Hello everyone, this is my first thread in this .NET forum. Since I am studying C#.NET in this semester, I reckon this would be just the right place for my asking questions regarding the C#...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.