python: making your own interned type

Status
You're currently viewing only dmitriyk's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

dmitriyk

Ars Tribunus Angusticlavius
8,804
A bit out of order, but...

[url=http:/civis/viewtopic.php?p=26425715#p26425715:3rx2xor7 said:
DavlinLotze[/url]":3rx2xor7]
2) I foresee my program depending on interning for more than just reducing memory footprint. It would allow me to make changes to just one object and have it take effect broadly instead of having to walk/search some huge complex tree and change each matching object.
1) That's not interning. Suppose you instantiate two objects, a and b, such that a.some_core_attribute != b.some_core_attribute, and then change b such that a.some_core_attribute == b.some_core attribute. What the hell happens to the interned objects? Consider the reverse case as well. Interning and mutability are mutually exclusive.
2) I really hope you're writing a single-threaded application.

1a) (Optimally, I'd like a system where I can just turn the interning on or off, or somewhere in between with just a change of a few variables - that would allow me to compare CPU/memory usage patterns, or tune it according to a particular usage case.)
This fundamentally conflicts with your point number 2.

1) If there's some way I can arrange things at an earlier stage - without the recycling implemented - that would prevent me from having to rewrite a bunch of code and interfaces later, I'd like to know.
Again, this fundamentally conflicts with point number 2. If you're relying on behavior described therein, the system will have to be designed and implemented with that functionality in mind. That behavior is more significant than just a memory optimization and will be difficult to implement later.

If your some_core_attribute is complex to calculate, just hash it on update and check the hash on equality comparison. With proper interning, you'd have to perform that some_core_attribute calculation on every object instantiation anyway (and have to transition to immutable objects).
 
Status
You're currently viewing only dmitriyk's posts. Click here to go back to viewing the entire thread.
Not open for further replies.