In C ++, destory (), deallocate (), and delete functions are correlated and distinguished. destorydeallocate

Source: Internet
Author: User
Tags types of functions

In C ++, destory (), deallocate (), and delete functions are correlated and distinguished. destorydeallocate

  

Here, we need to take a closer look:

Destory (): it shows that calling an object's destructor is equivalent to releasing an object. Some dynamic memory needs to be released to prepare for the next release of the object.

Deallocate (): Truly releases a memory block. This is an upper-layer encapsulation, that is, the upper-layer encapsulation of the delete function in the STL space configurator. It may call delete and return it to the OS. It may be stored in the memory pool, but for users, it is to release the memory block..

Let's look at an example to understand the true meaning:

 

#include <iostream>#include <stdlib.h>#include <unistd.h>using namespace std;class A{public:A(){data=new char[1000000];}~A(){//free the data memorydelete []data;}private:char *data;};int main(int argc,char* argv[]){for(;;){A *a=new A;std::allocator<A> allocat;allocat.deallocate(a,sizeof(A));}return 0;}

Obviously, this will cause problems, and an exception will be thrown during a certain period of time. Therefore, deallocate only releases the object memory and does not call the object constructor to release the dynamic memory in the object. Note that if a allocat. destory (a) is called, the program will not have bugs.

Therefore, in C ++, memory leakage occurs when objects are released and dynamic memory is released in objects.

Here, the delete operation symbol itself has two actions: Calling destructor 2 to release the memory. However: operator delete only releases the memory. The deallocate function is encapsulated based on the operator delete function. Remember this.

By looking at the STL source code, we can find that the Destructor like vector () have two operations: destory () to release the dynamic memory in the object (if any) deallocate is to release the memory occupied by the object itself. By using these two points, we can ensure that the memory cannot be leaked. Hey, I will talk about it here. It is also written for memory and convenience for future reference.


The difference between delete and destory In the destructor in c ++ is:

Delete is the first address of the given address, releasing the size of the object from the space to the system. If the object is a class object, it still calls the destructor.
A destructor is a class that parses a base class from a derived class, releases the inner space of a member variable, and finally releases the base class.

As for how the system recycles these spaces, it is unnecessary for the landlord to go further.
When an object is no longer used, it should be recycled in time to release the memory occupied by the object. You can call a logout method to undo the object, which releases the memory allocated to the object. The logout method is the structure method. The constructor name can also be any legal identifier, but it is usually declared using the Destroy identifier.
In C ++, when an object leaves the scope, the destructor of the object declared statically is automatically called, and the dynamically applied object must use the Delete keyword to execute the destructor.

What is OpenGL?

Of course there are built-in !! Run DXDIAG!

OpenGL 3D graphics standards are developed by AT&T's UNIX Software lab, IBM
, DEC, SUN, HP, Microsoft and SGI
Open graphics library, which enables 3D authenticity on a microcomputer
It is possible to generate and display sensory images. Since OpenGL is an open graphical icon
Quasi. OpenGL graphics software originally developed in UNIX can be easily transplanted to micro
On Windows NT/95. In Visual C ++ 4.1 (VC ),
An OpenGL-based 3D realistic graphics application is developed.
It is described as follows.

OpenGL Development Environment on Microcomputer

Applications developed based on OpenGL must run on 32-bit Windows
Platform, such as WindowsNT or Windows95 environment; Dynamic
OpenGL32.DLL and Glu32.DLL libraries. These two files are
Automatically loaded to the C: \ WINNT \ SYSTEM32 directory (assume that the user
). For Windows 95 Platform Users, you must manually
Copy the two dynamic libraries to the SYSTEM subdirectory of the Windows95 directory. Installed
After WindowsNT/95 and VC4.1, you can develop 3D Images Based on OpenGL.
Basic Conditions of software.

Basic steps of OpenGL program design

1. OpenGL Running Mechanism in WindowsNT

OpenGL works in Client/Server mode.
Applications developed based on OpenGL are sent to servers (OpenGL core mechanism ).
The server is responsible for interpreting commands. Normally
It runs on the same microcomputer as the server. Due to the running mechanism of OpenGL
Is the Client/Server mode, which allows users to conveniently
OpenGL is used in the network environment. This implementation method of OpenGL on WindowsNT is usually
Network transparency.

OpenGL graphics library functions are encapsulated in the dynamic link library OpenGL32.DLL,

All OpenGL function calls in the client are sent to the server
WinSrv. DLL implementation function, and then send the processed commands to the Win32 device drive
DDI allows you to generate images on a computer screen.

If OpenGL graphics accelerator is used, two
Driver: OpenGL client module (OpenGLICD) will be installed on the client; hard
The specified DDI will be installed on the server, at the same level as WinDDI.

2. OpenGL library functions

To develop OpenGL-based applications, you must first understand the library function of OpenGL.
Number. OpenGL function commands are quite regular. Each library function has a prefix of gl.
, Glu, aux, respectively, indicates that the function belongs to the basic OpenGL library, utility library, or auxiliary
Library. OpenGL in WindowsNT contains more than 100 core functions.
And supports the following four types of functions:

OpenGL utility library functions: 43, prefix with glu;
OpenGL auxiliary library functions: 31, prefixed with aux;
Windows dedicated library functions (WGL): 6, with wgl as the prefix;
Win32API functions (WGL): 5 with no prefix.

The 115 core functions of OpenGL provide the most basic functions.

3D modeling, establishment of illumination model, reverse sample, texture ing, etc. OpenGL
Library functions are at the top layer of core functions, which provide simple calls
The essence of the method is to call core functions to reduce developers' programming.
Workload; OpenGL auxiliary library functions are some special functions for beginners
Familiar with the programming mechanism of OpenGL, but applications that use helper library functions only
Can be used in Win32 environment,... the remaining full text>

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.