Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » T* Detach() for ArrayMap
T* Detach() for ArrayMap [message #24874] Tue, 02 February 2010 16:31 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi there

i ran into the need of
T* ArrayMap<K, T>::Detach(const K & key)

function. normal Array<T> *does* have one
T* Array<T>::Detach(int i);

since one can do a
T & Add(const K & key, T * newt)


on both, Array<T> and ArrayMap<K, T>, it would be consistent to have a Detach() function on both cotainer types.

so maybe the following lines could be added to Map.h
T* Detach(int i) { T *t = &B::value[i]; B::key.Remove(i); return t; }
Re: T* Detach() for ArrayMap [message #24881 is a reply to message #24874] Tue, 02 February 2010 22:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 02 February 2010 10:31

hi there

i ran into the need of
T* ArrayMap<K, T>::Detach(const K & key)

function. normal Array<T> *does* have one
T* Array<T>::Detach(int i);

since one can do a
T & Add(const K & key, T * newt)


on both, Array<T> and ArrayMap<K, T>, it would be consistent to have a Detach() function on both cotainer types.

so maybe the following lines could be added to Map.h
T* Detach(int i) { T *t = &B::value[i]; B::key.Remove(i); return t; }



Hm, is that correct implementation?

I would say something like

T* Detach(int i) { B::key.Remove(i); return B::value.Detach(i); }


is the correct one?

Another problem there is that this kind of detach is quite slow. Maybe we need DetachUnlink too (?).

Mirek
Re: T* Detach() for ArrayMap [message #24883 is a reply to message #24881] Wed, 03 February 2010 06:57 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
you're absolutely right, this one's better. Smile should have looked before..

the goal was just to be able to switch from Array to ArrayMap, when i.e one gets the impression, well i need to speed up things, or need to change stuff, so just to enhance it in one place, and supply the keys in the other places, without the need of doing lot of workarounds to replace missing behaviour.

Detach() slowness was not the main goal in that, though having it done faster is precious. one should at least be able to separate an obejct from a ArrayMap again (which maybe were constructed outside the map and added).

this kind of aproach is not possible for Vector and VectorMap though, the objects are stored on a consequtive mem space, which can only be Removed(). but Vector/VectorMap requires to have a Mouvable object (objects are reorganized on storage space during growth/shrink of vector), so why not having same Detach() also here? which would simply copy the stored object to a decent new place and return pointer? maybe because its no real "detach".. but it would make life esier, when exchanging vector to array, array to map or waht ever. dont know for sure if it makes sense.

DetachUnlink also makes sense, to say simply "stay in background until reactivated..".. but how would you reactivate such one?
Re: T* Detach() for ArrayMap [message #24890 is a reply to message #24883] Wed, 03 February 2010 11:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Wed, 03 February 2010 00:57

you're absolutely right, this one's better. Smile should have looked before..

the goal was just to be able to switch from Array to ArrayMap, when i.e one gets the impression, well i need to speed up things, or need to change stuff, so just to enhance it in one place, and supply the keys in the other places, without the need of doing lot of workarounds to replace missing behaviour.

Detach() slowness was not the main goal in that, though having it done faster is precious. one should at least be able to separate an obejct from a ArrayMap again (which maybe were constructed outside the map and added).

this kind of aproach is not possible for Vector and VectorMap though, the objects are stored on a consequtive mem space, which can only be Removed(). but Vector/VectorMap requires to have a Mouvable object (objects are reorganized on storage space during growth/shrink of vector), so why not having same Detach() also here? which would simply copy the stored object to a decent new place and return pointer?



It is not quite typical situation. If you really need something like that, you can use Swap, which leads to similar results...

Quote:


DetachUnlink also makes sense, to say simply "stay in background until reactivated..".. but how would you reactivate such one?


Good point Smile

Mirek
Re: T* Detach() for ArrayMap [message #24891 is a reply to message #24890] Wed, 03 February 2010 11:26 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Detach added.

Mirek
Previous Topic: VC2010
Next Topic: Symlink/Shortcut support
Goto Forum:
  


Current Time: Mon Apr 29 10:15:21 CEST 2024

Total time taken to generate the page: 0.02804 seconds