MESSAGE
DATE | 2011-04-06 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] C++ Workshop, Linked List Workshop - usenet article.
|
Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!feeder.news-service.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Yannick Tremblay Newsgroups: comp.lang.c++ Subject: Re: Destructors can copying objects Date: Wed, 6 Apr 2011 11:12:43 +0000 (UTC) Organization: A noiseless patient Spider Lines: 51 Message-ID: References:
Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Wed, 6 Apr 2011 11:12:43 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="A/ypJWiYGhwl1LX8PsXfBA"; logging-data="13334"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX1+negBFW9QRZMoLEAxN3xeDdvtpwuIeozI=" User-Agent: slrn/0.9.9p1 (Linux) Cancel-Lock: sha1:pOoDTDVPjXkW5VbHnKS3WaXk1+o= Xref: panix comp.lang.c++:1083058
On 2011-04-05, Ruben Safir wrote: > > But I'm distressed at this point because I don't want two copies of > all > the nodes. I want one series of nodes, which are created in free > memory > on the stack, handled in all possible scopes. The nodes themselves > are > 'self aware" of their positions in the list in that they have the > information of they're position in the nodes. The List object itself > does nothing more that communicate with the nodes. If I copy the List > Object, I don't want to duplicate the nodes as well. They're on the > heap, and then can stay there.
Are you sure about the behaviour you want?
You have a List. The list contains Nodes. The Nodes contain a pointer to some data.
What behaviour do you want when you copy a list?
What behavious do you want when you copy a node?
What behaviour do you want when you destroy a list?
What behaviour do you want when you destroy a node?
Don't worry about optimization for now. Worry about correctness and consistency.
Does the Node own the data it points to? - If yes: then the node most delete the data when the node gets destroyed - If no: the node only refers to the data that is external. The node can go away without affecting the data. Lifetime management of the data is done separately.
Should modifying a copy of a list affect the original list? List list1; // add ten element to list1; assert(list1.size() == 10); List list2 = list1; // Create a copy assert(list2.size() == list1.size()); // definite at this point // remove 2 element from list2 assert(list2.size() == 8);
// What about list1? Should it still contain 10 elements or 8?
Does the list owns the nodes it contains?
etc.
|
|