Map with BaseList2D as key [SOLVED]
-
On 23/07/2017 at 02:50, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform: Windows ;
Language(s) : C++ ;---------
Hello.I need to have a map with BaseList2D* as keys.
I know that if I'm about to store BaseList2D's somewhere, I have to do it in BaseLink.
Is there any maxon utility data structure for this case or do I have to create a HashMap<BaseLink, OtherType>.It appears that ignoring BaseLink and using directly BaseList2D* as keys is bad
since the same pointer probably will be used by Cinema 4D for another object if I delete the previous.Thank you for your time !
-
On 23/07/2017 at 04:45, xxxxxxxx wrote:
If you create and destroy the map in a single pass, you can
just use the BaseList2D pointer as the key. Otherwise, I
recommend using the UUID that you can retrieve withFindUniqueID(MAXON_CREATOR_ID)
I also recommend rebuilding the map that uses BaseList2D*
keys from that map with a single pass through the document.
You'd be able to rebuild that map in n*log(m) time (assuming
you're using a map with log(m) access time). I'm just
mentioning this because my initial thought was to search
the whole document for every entry but that would yield a
time complexity of n*m.Cheers,
-
On 24/07/2017 at 01:14, xxxxxxxx wrote:
Thank you NiklasR !
-
On 24/07/2017 at 02:50, xxxxxxxx wrote:
I guess, the actual question got already answered.
I just want to add a few words:
It is not per se bad to store a pointer to a BaseList2D. For example if you are owner of the pointed entities (i.E. you have full control about their destruction), there speaks nothing against it. The thing is, such a pointer can not easily be verified. And if the pointed entities are under Cinema 4D's control (e.g. object in object manager), the pointer may get stale and point to already free'd memory (if the user deleted an object for example) or even worse to memory already used for other means. Here the BaseLink is much superior and protects you from such mishaps. That's why we usually recommend to use BaseLink instead of pointers. -
On 24/07/2017 at 05:14, xxxxxxxx wrote:
Hello Andreas.
Originally posted by xxxxxxxx
And if the pointed entities are under Cinema 4D's control (e.g. object in object manager), the pointer may get stale and point to already free'd memory (if the user deleted an object for example) or even worse to memory already used for other means.
That was exactly the problem. The pointer was pointing to a different valid object from the hierarchy.
Thank you again for your time !