Results 1 to 2 of 2

Thread: "New" operator

  1. #1
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default "New" operator

    Hi all, today a question arised inside my mind:

    If I have a cycle like this:
    Classe *a;
    while( ... ){
    a = new Classe();
    }
    What happens?
    Will I continue on allocating new instances of Classe on the heap or the same part of memory is used at each allocation?
    Briefly,I mean for example, if I use an infinite cycle, will I run out of memory or not?

    The correct way would be
    Classe *a;
    while( ... ){
    a = new Classe();
    delete a;
    a = 0;//Optional
    }
    true?

    Thanks,

    Simone

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: "New" operator

    You will fill up the memory and eventually you will run out. It's like you said. You have to explicitly delete it to free the memory.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. new operator
    By QTInfinity in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2008, 12:56
  2. std::max_element and overload operator()
    By mickey in forum General Programming
    Replies: 2
    Last Post: 8th September 2008, 19:28
  3. overloading global "new" operator
    By mickey in forum General Programming
    Replies: 0
    Last Post: 10th April 2008, 18:01
  4. operator [] overloading
    By darksaga in forum General Programming
    Replies: 5
    Last Post: 8th April 2008, 16:27
  5. QString == Operator
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 27th December 2006, 18:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.