1.
Frequently accessed and modified variables, C has a good thing called register variables. The register declaration only applies to function parameters and auto variables. However, -- register variables can be compiled and ignored. That is to say, there is usually no need to use it in C ++ unless it is underlying hardware programming.
2.
Pointer variables must have a type specifier. For example, int * P. This statement is complete.
* Indicates that the address is stored, and INT indicates that the sizeof (INT) area from the address indicated by P indicates the memory area.
I am always confused. Although I know the int size, how does the operating system know it? I know that int32 * P is the starting address of a 4 byte long region, but how does the operating system know? P itself does not contain space length information.
What's more, how does void * know the length of this region?
Originally... Yes:
The allocation address. Just like the structure that the C ++ object model uses to record UDT information, a struct is attached to the allocated region header to record the size of the region.
Reference: http://bbs.bccn.net/thread-81781-1-1.html
I found the house with the house room number. I inserted this sign at the door and wrote the book "Covering N pings ". That's simple.
That is to say, the actually allocated memory is always more than the applied memory.
3.
For classes and struct without complex constructors, the efficiency of malloc is no different from that of new.
The gap between millions of DEBUG objects is several milliseconds, and the gap between release objects is almost fixed.
(The efficiency of release is about debugging. What is the efficiency of vs for debugging, such as meter link acceleration ?)
In general, what is the difference between trees. If there is a constructor, of course it depends on the significance of this command.
# Include < Stdio. h >
# Include < Windows. h >
struct vec3f
{< br> /// vec3f (): X (0.f), y (0.f), Z (0.f) {;}
float X;
float Y;
float Z;
};
struct vertexbuffer
{< br> vec3f point;
vec3f normal;
float texcoord [ 2 ];
};
IntMain ()
{
Const IntNum= 1000000;
IntBegintick, endtick;
Begintick = Gettickcount ();
Printf ( " New begin: % d \ n " , Begintick );
For ( Int I = 0 ; I < Num; I ++ )
{
Vertexbuffer * TMP = New Vertexbuffer;
Delete TMP;
}
Endtick = Gettickcount ();
Printf ( " New end: % d, used: % d \ n " , Endtick, endtick - Begintick );
Begintick= Gettickcount ();
Printf ( " Begin: % d \ n " , Begintick );
For ( Int I = 0 ; I < Num; I ++ )
{
Vertexbuffer * TMP = (Vertexbuffer * ) Malloc ( Sizeof (Vertexbuffer * ));
Free (TMP );
}
Endtick = Gettickcount ();
Printf ( " End: % d, used: % d \ n " , Endtick, endtick - Begintick );
System ("Pause");
Return 0;
}