473,406 Members | 2,281 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.

ownership problem?

Is it correct to say that the typical ownership problem, which frequently
arises in C++, does not occur normally in Python?

Best regards,
Gabriel.

--
/-----------------------------------------------------------------------\
| Any intelligent fool can make things bigger, more complex, |
| or more violent. It takes a touch of genius - and a lot of courage - |
| to move in the opposite direction. (Einstein) |
\-----------------------------------------------------------------------/
Nov 22 '05 #1
17 1672
Gabriel Zachmann a écrit :
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What is this "typical ownership problem" ?
Nov 22 '05 #2
Gabriel Zachmann a écrit :
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What is this "typical ownership problem" ?
Nov 22 '05 #3
Gabriel Zachmann <za**@in.tu-clausthal.de> wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


Could you explain what you mean by "the typical ownership problem"?

--
\ "Jealousy: The theory that some other fellow has just as little |
`\ taste." -- Henry L. Mencken |
_o__) |
Ben Finney
Nov 22 '05 #4
Gabriel Zachmann <za**@in.tu-clausthal.de> wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


Could you explain what you mean by "the typical ownership problem"?

--
\ "Jealousy: The theory that some other fellow has just as little |
`\ taste." -- Henry L. Mencken |
_o__) |
Ben Finney
Nov 22 '05 #5
Gabriel Zachmann wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?
Nov 22 '05 #6
Gabriel Zachmann wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?
Nov 22 '05 #7
Jeffrey Schwab wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?


the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...

</F>

Nov 22 '05 #8
Jeffrey Schwab wrote:
Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?


the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...

</F>

Nov 22 '05 #9
Fredrik Lundh wrote:
Jeffrey Schwab wrote:

Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?

the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...


Yes it is. Memory is only one type of resource. There are still files
and sockets to close, pipes to flush, log messages to be printed, GDI
contexts to free, locks to release, etc. In C++, these things are
generally done by destructors, which are called automatically and
deterministically. I am not a Python Guru, but in Perl, Java, and other
languages that have built-in garbage collectors, these tasks have to be
done explicitly. I find that this forces a procedural approach, even in
an otherwise object-oriented program.

If you want something like automatic garbage collection in C++, I
recommend the use of Factories with destructors that release the
Factories' products. The zeitgeist in c.l.c++.moderated seems to prefer
the use of smart (reference-counted) pointers, which also rely on
destructors to release resources automatically. Plentry of free,
open-source implementations are available.
Nov 22 '05 #10
Fredrik Lundh wrote:
Jeffrey Schwab wrote:

Is it correct to say that the typical ownership problem, which
frequently arises in C++, does not occur normally in Python?


What "typical ownership problem" do you feel frequently arises in C++?
If you are referring to the sometimes difficult task of determining
which object owns a particular resource, why would it occur less in
Python than in C++?

the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...


Yes it is. Memory is only one type of resource. There are still files
and sockets to close, pipes to flush, log messages to be printed, GDI
contexts to free, locks to release, etc. In C++, these things are
generally done by destructors, which are called automatically and
deterministically. I am not a Python Guru, but in Perl, Java, and other
languages that have built-in garbage collectors, these tasks have to be
done explicitly. I find that this forces a procedural approach, even in
an otherwise object-oriented program.

If you want something like automatic garbage collection in C++, I
recommend the use of Factories with destructors that release the
Factories' products. The zeitgeist in c.l.c++.moderated seems to prefer
the use of smart (reference-counted) pointers, which also rely on
destructors to release resources automatically. Plentry of free,
open-source implementations are available.
Nov 22 '05 #11
Yes!
Python uses auto garbage collection. As soon as the object reference
count becomes 0 it is removed from existence. So the problem typical
for C/C++: accessing pointers
to already deleted objects does not exist in Python.

Nov 22 '05 #12
Yes!
Python uses auto garbage collection. As soon as the object reference
count becomes 0 it is removed from existence. So the problem typical
for C/C++: accessing pointers
to already deleted objects does not exist in Python.

Nov 22 '05 #13
Jeffrey Schwab wrote:
the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...
Yes it is. Memory is only one type of resource.


Python's garbage collector deals with objects, not memory.
I am not a Python Guru


from the sound of it, you haven't written serious programs in any of the
languages you mention.

</F>

Nov 22 '05 #14
Jeffrey Schwab wrote:
the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a
garbage-collected language...
Yes it is. Memory is only one type of resource.


Python's garbage collector deals with objects, not memory.
I am not a Python Guru


from the sound of it, you haven't written serious programs in any of the
languages you mention.

</F>

Nov 22 '05 #15
Jeffrey Schwab <je**@schwabcenter.com> wrote:
...
You may be gratified to learn that Python's main storage model
is reference counted objects, and when an object falls out of
all referenced scopes its finalizers run immediately.
Thanks, that's good to know! For some reason I had it in my head that
Python always used mark & sweep. I'm used to ref-counted collection in
Perl, but I never relied on it because of a nagging (probably
ill-founded) worry about cyclic references. Does Python have any way
around this? Is there a Python equivalent to C++ destructors?


Python (main implementation, known as CPython) uses mark-and-sweep (with
generations &c) to deal with cyclic garbage -- but destructors (__del__
methods) *interfere* with cyclic garbage collection (there may be no
safe order of freeing a bunch of cyclic garbage when objects have
__del__ methods, and Python can't find it if there is, anyway).
I think Java has had a big influence, too. People just don't seem to
want to be bothered with thinking about object life cycles at all. This
seems unfortunate to me, because cleanup still has to be done, so it
just ends up getting moved outside the objects where it belongs. I
think this hurts abstraction.


Python 2.5 should introduce a 'with' statement that may go partways
towards meeting your qualms; it's an approved PEP, though I do not
recall its number offhand.
Alex
Nov 22 '05 #16
Alex Martelli wrote:
Python 2.5 should introduce a 'with' statement that may go partways
towards meeting your qualms; it's an approved PEP, though I do not
recall its number offhand.


http://www.python.org/peps/pep-0343.html

(this is one in a series of PEP:s based on the observation that the
generator machinery can be used for a lot more than iterators...)

</F>

Nov 22 '05 #17
> the problem isn't determining who owns it, the problem is determining
who's supposed to release it. that's not a very common problem in a


that's about what i meant.
i think, in c++, the "ownership problem" means the problem to determine who
and when is to delete an object, or to keep track thereof.
The object could be something as simple as a list element.

Best regards,
Gabriel.

--
/-----------------------------------------------------------------------\
| Any intelligent fool can make things bigger, more complex, |
| or more violent. It takes a touch of genius - and a lot of courage - |
| to move in the opposite direction. (Einstein) |
\-----------------------------------------------------------------------/
Nov 27 '05 #18

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

Similar topics

1
by: Ryan | last post by:
We have a DTS package developed on our development PC's (SQL 7). It runs fine. When we schedule it on the server (SQL 7), it fails. We have been able to find that this is a known issue down to the...
4
by: tarmat | last post by:
I've been using code such as the following, whereby I call the constructor of a class with an object allocated on the heap. The class is responsible for tidying up the memory. class Base{};...
11
by: Jacob | last post by:
I am trying to find the best way of documenting (in code and comments) ownership of secondary contained objects. This is my current status, and I would appreciate feedback on it: Case 1: ...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
2
by: Benden Ziyade | last post by:
Hello; I want to write a C program that check file ownership in /bin directory(ls, mkdir...). But I don't know how I start. I'm happy with your helping.
9
by: Andrew | last post by:
Apologies for the double-post.. I'm new, just getting used to this.. and should have posted this way in the first place.. How does one go about taking ownership of a registry key using C# & .NET...
7
by: Scott Gifford | last post by:
As a possible solution to a problem I'm trying to solve with an iterator (see an earlier post by me with subject "Iterator implementation questions: copy constructor and postfix increment"), I'm...
0
by: digz | last post by:
In the code below , a simplified version I need to pass a smart pointer to function f which I control .I cannot use std::auto_ptr as a parameter to f because it releases ownership on copy...
0
by: Stodge | last post by:
Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.