C ++ stack Analysis in C ++

Source: Internet
Author: User

If you want to learn C ++ stacks well, You Need To Know What C ++ stacks are. C ++ stacks are a data structure in which data items are arranged in order, data items can be inserted and deleted only at one end (called the top stack), which is divided into two parts: heap and stack.

In C ++, memory is divided into five areas: heap, stack, free storage, global/static storage, and constant storage. Stack is the storage area for variables that are automatically allocated by the compiler when necessary and clear when not needed. The variables are usually local variables and function parameters.

Heap is the memory blocks allocated by new. Their release compilers are not controlled and controlled by our applications. Generally, a new compiler corresponds to a delete. If the programmer does not release the program, the operating system will automatically recycle it after the program is completed. The free storage zone is the memory blocks allocated by malloc and so on. It is very similar to the heap, but it uses free to end its own life.

In the global/static storage area, global variables and static variables are allocated to the same memory. In the previous C ++ stack, global variables are divided into initialized and uninitialized ones, in C ++, there is no such distinction. They share the same memory zone. Constant storage area, which is a special storage area. It stores constants and cannot be modified (of course, you can modify them by improper means, and there are many methods)

Windows Services are designed for applications that need to run in the background and tasks that do not have user interaction. C (not C ++) is the best choice to learn the basic knowledge of such console applications. This article will establish and implement a simple service program.

The function is to query the number of physical memory available in the system, and then write the results into a text file. Finally, you can use what you have learned to write your own Windows Services. When I wrote the first NT Service, I went to MSDN to find an example. I found an article written by Nigel Thompson: "Creating a Simple Win32 Service in C ++". This article comes with a C ++ example.

Although this article explains the service development process, I still feel that the important information I need is missing. I want to understand what framework, what function to call, and when to call, but C ++ does not make me much easier in this regard.

The object-oriented method is convenient, but it is not conducive to learning the basic knowledge of service programs because classes encapsulate underlying Win32 function calls. This is why I think C is more suitable for writing basic service programs or implementing simple background tasks. After you have a thorough understanding of the service program, you can easily write it in C ++ stack.

When I leave my original job and have to transfer my knowledge to another person, using the example I wrote in C, it is very easy to explain the NT Service. A service is a console program that runs in the background and implements tasks that do not require user interaction. The Windows NT/2000/XP operating system provides special support for service programs.

People can use the Service Control Panel to configure the installed service programs, that is, Windows 2000/XP Control Panel | "service" in the management tool (or in the "Start" | "run" dialog box, enter services. msc/s-Translator's note ). You can configure the service to automatically start when the operating system is started, so that you do not have to manually start the service every time you restart the system.

  1. Differences between standard input implementation methods in C and C ++
  2. How does the C ++ compiler allocate storage space for Const constants?
  3. Basic Conception and method of C ++ Class Library Design
  4. Several Methods for converting C ++ Language
  5. How to better compile C ++ code

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.