본문 바로가기
Programming/Server

string copy performance test

by NoxLuna 2015. 1. 29.

Requests for assistance in person had known long ago, there was a chance to see the server program of the company. Report the contents of the program, so if the program would not do, we had the idea to keep the server There you cause that is causing the problem.


It had no time to look at all the sources of the problem, the problem itgetjiyo services freely to see the source of the other companies. So boatneundeyo at only source that caused the problem, the contents of which were written by the strcpy function immediately be caught in one eye. To put a copy in every guild name strcpy function on your friends list in your user profile structure report, I would, make a copy in advance guild structure Guild Profile Guild Profiles database, player profile, friends list, I could have just simply link and we think. But I think the way to a revised relationship was not mentioned in the days to fix many of the program's source code.


The strcpy function which can be a problem with the first is that it can cause a serious program error. Of course, you must use the strcpy function than strncpy function or strcpy_s function. Where is the program, or yeotdamyeon database fields had a string of a larger space than the space you want to copy an array or a null character has been lost state, strcpy raises a very serious problem. If you use the strncpy function, strangely enough, showing the end of an error.


Second is the issue of the right performance. strcpy function has no choice but to continue to have the logic to test the null character is. Than always read every character, because the null character inspection by the if statement, increase the number of instructions to be performed and pipelines corruption issue exists.


 

s

t

r

i

n

g

\0

         

 


"string" is a '\ 0' character in the subsequent six letters to a very important role. '\ 0' character will indicate the end of a string. Because of this, many programmers to define a string in the following format to define an array of strings.

 

char str [MAX_CHAR + 1];

 

In my case I do not add '1' for string terminated character. When you enter such a structure to generate a meaningless padding, because even if you put a + 1 can be handled efficiently and more safely. When you copy a string strcpy instead of using strncpy or memcpy. When the output string of the format string output form part of the form, use a "% .16s" form.

 

The rest of the array value in the future, '\ 0' characters in the string are garbage values. That is, data that has no meaning in program execution. If you need to use the strcpy function or strncpy function, the array that is the end destination just be meaningless garbage. Nor why I use the memcpy function does not have some sort of problem, but rather safer in security in many cases. Many programmers will erase the contents of the array after declaring an array for security to zero. However, if you use the memcpy will only give details of the source string is cleared to zero.

 

Note if the size of the array that is a source must be equal to or greater than the size of the array that is the destination. In fact, most programs only small though significant angetji not a problem, it is recommended that you do not use.

 

The problem is that the performance bottleneck in the server program memory (Bottlenect) phenomenon. Would be a good way to design a program to prevent, if possible copying memory. Sometimes, but can also destroy a structured form, always in mind the grounds of'd need a program.

 

Here is a simple performance test results to the strncpy function with memcpy function tests. 


 

memcpy() C function is also carried out gradually increase the size in which you want to copy neuleonaneunde time, because the memory block is relatively inexpensive compared to the cost of the copy settings for copying costs. It can be seen that compared strncpy function is still growing. Typically, the name of the game is to use a 16-byte or 32 bytes, if the trend of using Unicode, such as today will be a lot of 32 bytes. In this case, the use of memcpy function, the speed improvement comes in the strncpy used by approximately two-fold. If such a case occurs and chat messages is nearly five times the speed difference. Look what I can see seem to use this result for granted.

 

'Programming > Server' 카테고리의 다른 글

Making high resolution performance counter  (0) 2015.01.29

댓글