Summarize stack objects referenced in C ++/CLI

Source: Internet
Author: User

C ++/CLI is. the C ++ language on the NET platform, of course, the syntax of iso c ++ is retained, and the stack object is one of them, but its semantics has changed, when an object is returned, the memory occupied by the object is automatically released.

Everyone knows. the biggest difference between the NET platform and the win32 platform is the managed memory. Anyone who knows about C # knows that C # contains value type and refrence type ), value Type objects are allocated to the stack, and all referenced objects are allocated to the managed stack.

In other words, the object type determines the allocation location, stack or managed stack. The collection of stack memory is still the same as in the past. It is deterministic. The collection of managed heap memory is the responsibility of the garbage collector. However, in such a memory model, what is the meaning of MyClass myClass; in C ++/CLI?

As we all know, the emergence of advanced languages is mainly attributed to the compiler, And the semantics depends on the Compilation results of the compiler. The following describes some simple code. Pay attention to the comments in the code.

 
 
  1. private:  
  2. class SingleTonTranslator  
  3. {  
  4. public:  
  5. SingleTonTranslator()  
  6. {  
  7. signal(SignalExceptionClass::GetSignalNumber(),   
  8. SignalHandler);  
  9. }  
  10.  
  11. static void SignalHandler(int)  
  12. {  
  13. throw SignalExceptionClass();  
  14. }  
  15. };  
  16.  
  17. public:  
  18. SignalTranslator()  
  19. {  
  20. static SingleTonTranslator s_objTranslator;  
  21. }  
  22. };  
  23.  
  24. // An example for SIGSEGV  
  25. class SegmentationFault : public ExceptionTracer, public   
  26. exception  
  27. {  
  28. public:  
  29. static int GetSignalNumber() {return SIGSEGV;}  
  30. };  
  31.  
  32. SignalTranslator<SegmentationFault>   
  33. g_objSegmentationFaultTranslator;  
  34.  
  35. // An example for SIGFPE  
  36. class FloatingPointException : public ExceptionTracer, public   
  37. exception  
  38. {  
  39. public:  
  40. static int GetSignalNumber() {return SIGFPE;}  
  41. }; 

I have read countless articles describing the complexity of C ++, and I have discussed the complexity of C ++. I wrote two articles about C ++ ). I have always felt like a blind person. As criticized by a reader of "Why C ++.

In this article, I did not specify what is C ++'s "non-essential complexity ". Of course, I can know it by myself, and even if I have been in contact with C ++ for a while, however, new users or even non-beginners have no specific understanding of what I call "non-essential complexity, this leaves the article "Why C ++" out of its original intent-oriented to all C ++ users and learners.

For the same reason, after writing the article "How should you learn C ++/CLI?", Mr. Meng asked me to write a series of articles for "programmer, let me introduce my attitude and understanding changes in the process of getting in touch with C ++, although I am very happy to agree.

However, until now, three months have passed, and the particles have not been collected. Why? Because I don't think the real nature of the problem is clearly touched; so I haven't done anything until now, so I don't want to talk nonsense, except for being able to read as a novel, it may not be of any practical use to those who really want to learn or even use C ++/CLI.

  1. Introduction to C ++
  2. Summary Notes on learning and exploring C ++ library functions
  3. Basic Conception and method of C ++ Class Library Design
  4. Does C ++ really have market value?
  5. Basic Conception and method of C ++ Class Library Design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.