Results 1 to 13 of 13

Thread: Can't delete an object (instance of structure with a nested structure)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Can't delete an object (instance of structure with a nested structure)

    Quote Originally Posted by tonnot View Post
    So, my final conclusion is that in any way deleting an object and inmediatelly create can to have no effect. (I have seen some links about it on the web ). Am I right ?
    No, you are wrong.

    And I final stupid question, why C++ initialized some vars to max values (in example a int to 65535) ????
    C++ doesn't initialize any of your values. They are either random values residing in the chunk of memory where the variable is created or the compiler preinitializes the variables with some known value (often called a "canary") in debug mode. Seeing such value (it's usually multibyte) should make you aware it is related to an uninitialized area of memory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: Can't delete an object (instance of structure with a nested structure)

    Somebody has tell me at other forum ( about deleting)
    The OS merely marks the memory block as free - it does not have to do anything else and certainly it does not have to do anything immediately
    So if you do what you did, and immediately try to use the object again, you may find valid values.
    So, maybe a delete follow by an inmediatelly new can have no effect ?
    Thanks WY

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Can't delete an object (instance of structure with a nested structure)

    What do you mean by "no effect"? If you delete an object then its destructor gets called. Then when you create an object then it may be located in a different or the same address in memory and the constructor gets called. If you access an area of memory where an object once was and nothing overwrites this area in the meantime, you'll be reading values that used to belong to the object. If you mean that you can get the same values after reallocating an object, then yes, you can get the same values. If all memory space is preinitialized with zeroes and you don't initialize any memory yourself then every object will contain only zeroes, with or without deleting anything. But they will certainly be different objects.

    Tonnot -- programming is not only about knowing syntax of some programming language. It's also, or rather mainly, the knowledge of how computers work, why they work this way and what "physical" result each statement of your program has. It is obvious you are missing all those skills. Do everyone (yourself included) a favour and read a good book on computers and spend an hour a day on the Web reading and understanding how computers work. And I don't mean asking on forums but reading papers and books on computer science. You will save yourself a lot of time and nerves this way. And investing in a couple of English lessons (especially grammar) would be a good thing to do as well, sometimes it is very hard to understand what you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Tree structure
    By ikm in forum Newbie
    Replies: 1
    Last Post: 7th August 2009, 20:19
  2. Folder structure of Qt SDK
    By piotr.dobrogost in forum Installation and Deployment
    Replies: 19
    Last Post: 14th July 2009, 09:17
  3. Treeview Structure
    By bismitapadhy in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 13:44
  4. Data Structure help!
    By darshan in forum Newbie
    Replies: 8
    Last Post: 18th February 2009, 12:47
  5. Structure and pointers
    By zorro68 in forum General Programming
    Replies: 3
    Last Post: 22nd October 2007, 14:38

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.