We help IT Professionals succeed at work.

difference between  two functions

Vlearns
Vlearns asked
on
could someone help me understand the what this function does?
ngx_copy
http://lxr.evanmiller.org/http/source/core/ngx_string.h#L112

and
ngx_cpymem

http://lxr.evanmiller.org/http/source/core/ngx_string.h#L89


what is the difference between the two, when would you use one over the other


thanks!
Comment
Watch Question

Expert of the Quarter 2010
Expert of the Year 2010

Commented:
As the comment states,

/*
* the simple inline cycle copies the variable length strings up to 16
* bytes faster than icc8 autodetecting _intel_fast_memcpy()
*/

If the compiler version is     __INTEL_COMPILER >= 800
it defines the function  ngx_copy  inline because the specific inline code will be faster than the compiler can do it using ngx_cpymem.

It is otherwise defined as just a macro that points to ngx_cpymem, which in turn is a macro around ngx_memcpy or memcpy (depending on another switch).

I would always use ngx_copy, which will internally compile to whatever is most efficient for the platform.

Author

Commented:
hi

thanks

but what does this do

why does he add n in the end?

#define ngx_cpymem(dst, src, n)   ((u_char *) ngx_memcpy(dst, src, n)) + (n)
Expert of the Quarter 2010
Expert of the Year 2010
Commented:
I believe at the end of the copy, the pointer is at the end of the data copied, not the beginning.