Results 1 to 10 of 10

Thread: managed c++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: managed c++

    Quote Originally Posted by wysota View Post
    Dangerous? How come?
    I think one reason of managed heap was have code more secure (from programming error). I I still have in mind that "managed stack", thinking that there is a runtime that take some action on the stack..
    Then what's the reasons to permit objects on the stack instead of heap? (is it useful and when? I don't see any reason to have obj on the stack [apart a bit speed])--
    Regards

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

    Default Re: managed c++

    Quote Originally Posted by mickey View Post
    I think one reason of managed heap was have code more secure (from programming error).
    But from what kind of errors? What is so error prone with allocating data on stack?

    Then what's the reasons to permit objects on the stack instead of heap? (is it useful and when? I don't see any reason to have obj on the stack [apart a bit speed])--
    Stack allocated objects will automatically be destroyed when they go out of scope. That makes it easier to use them compared to heap allocated objects and it prevents memory fragmentation.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: managed c++

    then, I'm just wondering wich kind of object is convenient to allocate on the stack instead of the heap? Or there is no difference and .Net has introduced objecst on the stack only to do something more?
    Furthermore: what could happen if I write a c++ managed program and I send every objects on the stack?
    Regards

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

    Default Re: managed c++

    Don't try to look for differences where there are none. The difference between stack allocated objects and heap allocated objects is the area of memory (hence pointer address) they are located in and automatic deallocation of stack based objects. Nothing more really.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: managed c++

    sorry, but if an object goes on the stack, the runtime should perform less action at run time (maybe nothing operations). Is it so?
    Regards

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

    Default Re: managed c++

    The only difference is that the memory is allocated in one go for the stack as a whole instead of each object separately, but in practice the operating system optimizes allocations by allocating a whole page as a pool and then serving the already allocated memory. Basically the allocation penalty can be ignored as long as you do anything else than just allocating and deallocating memory

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 09:45
  2. Sending a shortcut to an exec managed by QProcess ?
    By Ti_Thom in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2007, 17:31

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.