User Tools

Site Tools


qt:heap_versus_stack

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
qt:heap_versus_stack [2010/12/08 22:19] – [Heap or Stack?] mithatqt:heap_versus_stack [2010/12/08 22:58] – [Short answer] mithat
Line 1: Line 1:
 ====== Heap or Stack? ====== ====== Heap or Stack? ======
  
-Should Qt objects be created on the heap or on the stack? ((Reminder: the heap is the memory store from which dynamically allocated storage is taken; the stack is used for standard variable storage as well as for passing actual parameters to functions, etc.))+Should Qt objects be created on the heap or on the stack?((Reminder: the heap is the memory store from which dynamically allocated storage is taken; the stack is used for standard variable storage as well as for passing actual parameters to functions, etc.))
  
 ===== Short answer ===== ===== Short answer =====
 If the object is going to be part of a tree of Qt objects (as will be the case for most Qt GUI objects), then it should be created on the heap. If the object is going to be part of a tree of Qt objects (as will be the case for most Qt GUI objects), then it should be created on the heap.
  
-If the object is not part of a tree or is the root of a tree, then it can be created either on the heap or the stack. It seems to be a tradition (or maybe there's a good technical reason for this) to create the main ''QApplication'' object on the stack.+If the object is not part of a tree or is the root of a tree, then it can be created either on the heap or the stack. It seems to be a tradition (or maybe there's a good technical reason for this) to create the main ''QApplication'' object on the stack. It is also typical to create main windows (tree roots) on the stack so that they do not need to be manually deleted.
  
 ===== Long answer ===== ===== Long answer =====
qt/heap_versus_stack.txt · Last modified: 2010/12/08 22:59 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki