Results 1 to 10 of 10

Thread: managed c++

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

    Default managed c++

    Hi, I read this below of managed c++ and I has introduced objects on the stack? Does anyone know why (or wich advantages ) this? I think on the stack the manage of object should be more quick, but how many objects can take on it? I think not so many....What do you think, please?

    Qt Code:
    1. value class classB {
    2. private:
    3. int value;
    4.  
    5. };
    6. classeB^ bHeap = gcnew classeB(); //on managed heap
    7. classeB bStack; //on managed stack
    To copy to clipboard, switch view to plain text mode 
    Regards

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

    Default Re: managed c++

    On modern computers it doesn't really matter. Allocation on stack is a bit faster. And stack size is practically limited only with the amount of virtual memory.

    BTW. What is a managed stack? Is there anything to manage there?

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

    Default Re: managed c++

    Quote Originally Posted by wysota View Post
    And stack size is practically limited only with the amount of virtual memory.
    What do you want to say? ( I dont' understand the sense)
    BTW. What is a managed stack? Is there anything to manage there?
    I now on the stack is managed from some actions of OS...But I thought in that case, CLR take some action even on the stack (or to permit the object goes on the stack)
    Then what's the reasons to permit objects on the stack instead of heap (more larger). Aren't the objects on the stack more dangeroues? thanks
    Last edited by mickey; 14th September 2007 at 10:09.
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
    What do you want to say? ( I dont' understand the sense)
    That if the situation allows you to allocate either on stack or on heap, you can do as you want. Usually you allocate small amounts of memory on stack and big amounts of memory on heap. But if you need a big chunk of memory only within a single scope, you can allocate it on stack as well as it's not likely that you'll run out of stack (which used to be a real threat "in the old days").

    Aren't the objects on the stack more dangeroues? thanks
    Dangerous? How come?

  5. #5
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  7. #7
    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

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  9. #9
    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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.