Speaking so much, this is the last section of this article, which is the further optimization of the program.
This section, but also a few of the little thing,--!
1. Optimization of program logic and mechanism
2. Source-Level code optimization
3. Compiling optimizations for CPUs and operating systems
Q: Warrior, I've been there, sort of hash I'm getting used to it, it doesn't hurt, there are places that can be more exciting
A: Before we mentioned the detection of the situation is repeated, do not let the situation behind the same situation, leading to the infinite degeneration, unable to extricate themselves, there is the same can be counted as repetition
That is the failure of the situation, that there is no box can effectively push the situation, and then the situation will not be analyzed, directly delete it, then we will create a failure
The situation queue, the failure of the situation box coordinates and hashes and the location of the porter to save, the hash is for the hash calculation, and the coordinates are in case of in the event of the
If there is a repetition, the situation can not be solved, then the original use of the coordinate comparison, of course, the use of pure hash comparison when the coordinates are neither saved nor allocated memory.
Q: So this is all there is?
A: Similarly, the failure of the situation to the parent recursion, tagstage.slaves decrement, if dropped to 0, then the parent is also a failure situation, followed by guilt, also joined the queue of failure.
Q: Cool! I want to see the source right away, I want to see, I want to see ...
For:
Log failed scene Snapshot (temporarily incomplete test) int Fnstagesnap (Pqueue pqueue, Pstage pstage) {union {psnap psnap;//snapshot pointer byte *pdummy;}; Pshot Pshot;int dwret;pshot = pqueue->shots;if (pshot->count) {Psnap = (psnap) realloc (Pshot->snaps, pShot-> Size * (Pshot->count + 1));} Else{psnap = (psnap) malloc (pshot->size);} if (psnap) {pshot->snaps = psnap;//update pointer//psnap = &psnap[pnext->shots->count];//struct Variable size pdummy + = pShot- >size * pshot->count;psnap->position = Pstage->position;psnap->hash = pStage->Hash;//layout fingerprint if (( Pstage->flags & sgf_crc32) = = 0) {//Sort store coordinate details (as long as it is not returned, it will be undone back to the original, do not have to be sorted)//fnstagesort (Pnext->stars, NULL, psnap- >stars, Pnext->count); V32copy (Psnap->stars, pstage->series, sizeof (STAR) * pstage->count); pshot->count++;//Increment Failure situation number//up recursive parent scene, all the number of sub-scenes to be analyzed will be logged to the failure list and pop-up queue pstage = pstage->host;if (pstage! = NULL) {# Ifdef _debugfnprint ("Parent scene =0x%08x, number of remaining child scenes =%d.\r\n", Pstage, pstage->slaves);d Wret = Fnqueuerange (Pqueue, pStage); if (dwret <= 0) {fnPrint ("[Warning] scene 0x%08x is not in the active queue!\r\n", pstage); return 1;} if (pstage->slaves = = 0) {fnprint ("[Warning] scene 0x%08x has no sub-scene!\r\n", Pstage); return 1;} #endifpStage->slaves--;//Debugging is complete to ensure that the count is positive if (pstage->slaves = = 0) {#ifdef _debugfnprint ("Record parent scene =0x%08x to failed collection. \ r \ n" , pstage); #endifdwRet = Fnstagesnap (Pqueue, pstage); if (dwret <= 0) return dwRet-1; #ifdef _debugfnprint ("Remove the parent scene =0x%08 X.\r\n ", pstage); #endiffnQueueRemove (Pqueue, pstage); return Dwret + 1;//Returns the series}}return 1;} Fnstagecode (sec_cache_null); return 0;//insufficient memory, data unchanged}
Q: So, can there be a comparison of running effects?
For:
There is no failure queue, which is already in front, and is posted here again:
After joining the failed queue, note that the queue uses spikes, the remaining values and the number of steps are compared:
Q: Too tm God, have you? I want it, and I want it!
A: When we analyze a box for analysis, whether up or down, there is always a fixed order, for example, is up and down, probably the best way is the back direction
After getting the list of the way, according to the number of units from large to small to generate the scene, if not optimize the mechanism, the upper and lower left three directions will be generated analysis, and join this
mechanism, to the right of the number of the largest, first analyzed, in fact, one step completed, that is, immediately reach the optimal solution.
Q: The storm is gone. Do you have anything else?
A: Save some space for the later to play it, the following is the source-level optimization, such as internal pointers
Tagstage has several internal pointers that compute allocations as they apply for memory, rather than subsequent allocations, which are dynamically allocated in 32-bit Windows with 4 K as
Unit, you apply a byte is also 4 K, wasting memory, repeatedly applying for release, the process is complex and easy to write wrong, while easy to produce debris grenades ...
In addition, a one-dimensional array instead of several one-dimensional or multidimensional arrays, such as stars, simplifies memory management logic, see resource Bundle code
Furthermore, the use of inline assembly naked functions instead of library functions can significantly increase efficiency, such as memory replication, in V32.dll:
Copy two memory blocks, do not detect pointer void __declspec (naked) __stdcall fncopy (void *dst, const void *src, int len) {//debug mov esi, ESP, call completion CMP ESI, esp check stack//__asm{//mov edi, DST; [ESP + 4]//mov esi, src; [ESP + 8]//mov ecx, Len; [ESP + c]//rep movsb//}__asm{push esi; protection register ESI and EDI, the first variable from [esp+4h] to [esp+0ch], the second for +10hpush Edimov esi, [esp+10h]; string Operation original Start address mov edi, [esp+0ch]; String operation target Address mov ecx, [esp+14h]; String operation Count and ECX, 3; Copy the remainder rep MOVSB first; byte-bytes Copy mov ecx, [esp+14h]shr ecx, 2; Four of the quotient (number of double words) rep movsd; Double-word copy pop edipop Esiret 0ch; Bare function return (three parameters)}}
When you assign a value of two constructs, the compilation is actually similar to the instruction, and does not call functions such as memcpy.
It's like putting the comparison in the loop, there's a program to control the pointer, why do we have to test the pointer every time?
Finally, for the CPU and operating system optimization, the time is almost, do not say, Intel has a special compiler optimization tools.
In fact, I just write a small gift to Lotus sister happy, write here, also is dedicated, I hope the beauty of programming, can bring more laughter to the world, release more pressure and pain
My computer said, a lot of things on the TM to me!!!
To the full text of the best
Die Hard Ranger
2015-03-15 00:34:56
To the news: Push box game automatic solution algorithm Design (v)