Results 1 to 19 of 19

Thread: deleting internal pointer in QModelIndex

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #15
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanks
    4
    Thanked 6 Times in 4 Posts

    Default Re: deleting internal pointer in QModelIndex

    Quote Originally Posted by wysota View Post
    [code]YourModel model;
    Ok, I think you're maintaining here that the ModelIndexes get copied internally, and that copies get destroyed, willy-nilly, leaving some valid MI's around with the same internal pointer/id.

    That certainly does kill the idea of trusting them with a piece of memory - you'd have to implement a ref system that would be sensitive to copies and all of that - certainly adds more weight to the MI's.

    On Word Boundary Alignment/Packed Structures
    Hmm?

    $ uname -m
    i686
    $ gcc tst.c -o tst
    $ ./tst
    Struct S size: 8
    Struct S2 size: 1
    Struct S3 size: 5

    Care to comment?
    Blow me down! Two errors on my part:
    1. I'm used to the MS compiler on Intel, and the automatic inclusion of the 'Zp1' arg, which packs structs. Have taken that somewhat for granted.
    2. Was thinking more of passing arg word alignment issues vs. pack structs (which I don't think are an issue on Intel - you can prove me wrong with an example... )

    That said, a word devoted to back-pointer is still a word devoted to back-pointer, and is still 4bytes on a 32bit machine, and 8 bytes on a 64bit machine. Not a big deal for small models - a huge deal for large models.

    It is not "back". parent() is const, thus the direction is maintained (data pulled, not pushed).
    Ok, here's where I don't understand. Consider this:
    Qt Code:
    1. void *data;
    2. mymodel::index(...)
    3. {
    4. /* ( stack frame pushed for this call ) */
    5. ....
    6. return createIndex(r,c,data);
    7. /* ( stack frame pushed and popped for create call,
    8.   | popped again on return. */
    9. ...
    10. }
    11.  
    12. mymodel::parent(..., parent)
    13. {
    14. ...
    15. if (parent.isValid)
    16. {
    17. void* parentData = parent.internalPointer();
    18. if (parentData == data)
    19. qdebug("Isn't this the modelitem I created above?");
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    I guess I could prove the latter question by hanging on to the pointer of
    the created MI and see if it's the same. At any rate, if the ModelItem is not fed back to me, something that looks very much like it is.

    Consider this: (two really interesting coding examples)
    Ok, I'm studying these. Again, the crux appears to be that copies are happening spontaneously all over the place, is that correct?

    So, again (if true), I agree - it kills the idea of handing a piece of memory to the ModelItem. (Beyond performance questions.)

    <...snip...>
    So if you want your model to be safe, you have to get the data from the model and not from the index. My explanation might not be clear (it's late here) - in that case forget it and move on.
    I don't think we disagree, here: The real information is coming from the model - in the small structure context I've questioned about, the little items aren't data - they're just pointer holders. You can think of them as large pointers that have to be allocated. I'm expecting them to die quickly, I'm not expecting to hang on to them, I'm not expecting them to be valid any longer than the index (which, as we have discussed, is very short-lived.)

    But, again, if they're (the MI's) being copied internally and the dups are being destroyed, that certainly puts a hole in the notion. That's a valid issue.

    cheers,
    rickb
    Last edited by rickbsgu; 18th December 2007 at 14:13.

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2007, 14:51
  2. Replies: 2
    Last Post: 16th February 2006, 20:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.