473,406 Members | 2,956 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,406 software developers and data experts.

Masterlist, everything on heap?

Sorry I had no idea how to name my subject.
Is this good practise? :

Suppose I have a situation that's a bit like a relational database. I
have a list of objects A, a list of objects B, and I need to have a list
of objects C. But each object C has a list of a subset of the existing A
objects and a list of a subset of the existing B objects.

Most of the students I saw do this by making all the objects on the
stack (with 'new') and putting their pointers in lists, and of course
using those pointers in the construction of C objects..

But I thought, from reading "Thinking in C++ vol. 2" that this approach
was better? :

the main program does {
list<A> objectsA;
list<B> objectsB;
list<C> objectsC;
}

where

class C {
list<A*> objectsAptr;
list<B*> objectsBptr;
}

Of course, assuming I do all of this in the right order (first creating
the set of A's and B's, inserting them into the lists, and then using
the pointers from the elements in those lists to create C objects) and
ensuring that the entries in the C lists disappear when their
corresponding objects do.

But, this way I never have to deconstruct any objects manually, right?

But is there a hole somewhere in my reasoning? Assuming I'd have to be
able to delete A,B, and C objects from main_program and also
insert/change them.

thanks for any insight,

--
- gipsy boy
Jul 22 '05 #1
1 1196
gipsy boy wrote:
Sorry I had no idea how to name my subject.
Is this good practise? :

Suppose I have a situation that's a bit like a relational database. I
have a list of objects A, a list of objects B, and I need to have a list
of objects C. But each object C has a list of a subset of the existing A
objects and a list of a subset of the existing B objects.

Most of the students I saw do this by making all the objects on the
stack (with 'new')
If an object is "made with 'new'", it's in free store, not stack.
and putting their pointers in lists, and of course
using those pointers in the construction of C objects..

But I thought, from reading "Thinking in C++ vol. 2" that this approach
was better? :

the main program does {
list<A> objectsA;
list<B> objectsB;
list<C> objectsC;
}

where

class C {
list<A*> objectsAptr;
list<B*> objectsBptr;
}

Of course, assuming I do all of this in the right order (first creating
the set of A's and B's, inserting them into the lists, and then using
the pointers from the elements in those lists to create C objects) and
ensuring that the entries in the C lists disappear when their
corresponding objects do.
Yes, assuming...
But, this way I never have to deconstruct any objects manually, right?
If the pointers you store are those _to_ elements of the corresponding
lists, then the lists will destroy their own elements. So, right, you
will not have to.
But is there a hole somewhere in my reasoning? Assuming I'd have to be
able to delete A,B, and C objects from main_program and also
insert/change them.


You will discover any holes in your approach as you are implementing it.
So, go right ahead and take a stab at it.

V
Jul 22 '05 #2

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

Similar topics

0
by: ANt | last post by:
Hi, we have some major GC issues at present with a system we're trying to put live. It's a live calculation engine that's distributed across about 30 Java server processes. A set of processes...
14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
2
by: mordac | last post by:
Hello, I was wondering if I could get some opinions on how best to handle printing in a max heap data structure. Right now my heap struct looks as thus: typedef struct heapStruct { int*...
9
by: shine | last post by:
what is the difference between a heap and a stack?
3
by: toton | last post by:
Operator overloading has a sort syntax rather than member function call for stack based memory allocation. like complex<int> c1,c2,c3; c3= c1+c2; How the same can be applied to heap based...
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...
10
by: Woody Ling | last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger than 256MB for the following case.. 1. Intra-parallel is ON 2. Intra-parallel is OFF
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
4
by: ggoubb | last post by:
The purpose of the Insert function is to add a new integer in the Heap assuming that it is not already full. If Heap capacity has been reached, it attempts to double the current capacity. If capacity...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.