Does specifying memcpy s parameter type as int improve its speed

Updated on technology 2024-03-27
19 answers
  1. Anonymous users2024-02-07

    The standard library memcpy function defines the parameter type not of char * type, but void * memcpy(void *dest, const void *src, size t len);

    Here's the program I implemented:

    # include

    void *

    memcpy(void *dest, const void *src, size_t len)

    int32_t *idest = dest;

    const int32_t *isrc = src;

    char *cdest;

    const char *csrc;

    size_t ilen = len >>2;

    size_t clen = len & 1 <<2) -1);

    while( ilen-- 0 )

    idest++)= *(isrc++)

    cdest = (char *)idest;

    csrc = (char *)isrc;

    while( clen-- 0 )

    cdest++)= *(csrc++)

    return dest;

    Of course, the memcpy in the actual standard library is generally implemented in assembly language, which is more efficient.

  2. Anonymous users2024-02-06

    void file word(char *p) This function should not have a q variable in it, q is not visible to him, and q can be passed in. void file word(char *p,char **q) You can't compile, it's best to send the compilation error to everyone, help you analyze.

  3. Anonymous users2024-02-05

    should be memcpy(dst,src,size t len); That's fine. The third parameter of memcpy is len, which must be unsigned, and you define int len, so no, it is also preceded by size t len = 16

  4. Anonymous users2024-02-04

    1. Function prototype.

    void *memcpy(void *dest, const void *src, size_t n);

    2 functions. Copy n bytes from the start of the memory address referred to by the source src to the start of the memory address referred to by the destination dest.

    3. Header files required.

    c language with include ;

    4 return values. The function returns a pointer to dest.

    5 Instructions. It is possible to overlap the memory region that Destin refers to, but if the memory region that the source refers to overlaps with the Destin region, then this function does not ensure that the overlapping region of the source is overwritten before copying. Memmove can be used to deal with overlapping areas.

    The function returns a pointer to Destin.

    2.If the target array destin already has data, the memcpy() command will overwrite the original data (up to n). If you want to append data, after each execution of memcpy, increase the target array address to the address where you want to append data.

    Note: Source and Destin are not necessarily arrays, any read/write space is acceptable.

    Your question can be used.

    for(i=0; i<3; i++)

    for(j=0; j<3; j++)

    arr[i][j]=array[i][j];

    In lieu of.

  5. Anonymous users2024-02-03

    It is to open up a new memory space as large as the original array.

  6. Anonymous users2024-02-02

    In a 32-bit computer, each variable is stored at an address that starts in multiples of 4, which means that if you create a new variable, no matter what type it is, it will start with a multiple of 4.

    Although you do store all the internal things in this way, according to the computer's coding display reasons, you can directly see that the things generated after compilation are garbled or do not meet your requirements.

    You can compare the original stored binary code with the original, and it should be the same.

    And int x=10; The int here should be 4 bytes, writedata(&x,2); should be writedata(&x,4);

  7. Anonymous users2024-02-01

    Although many books say that int and char are interconnected, in fact, the current form is that int occupies 4 bytes, and char occupies 1 byte. memcpy is a string handler. So it's wrong for you to use int directly for the address like this, and int and char are not incompatible.

    It's just that it's generally easy to get it wrong. I'm afraid that the only common value is 0. Because the value of 0, int is four bytes, and the value of 32 bits of the four words is 0, and the value of char is 0 when a byte 8 is 0, then char and int will work.

    But even if it's 0, many people get it wrong.

    x is int, you need to convert the value of x 10 to the string "10" first, so write a character array xx to store the value of x to the string, so writelnint has to be changed. Write it as follows ().

    void writelnint(int i) at the same time, I also need to change my writedata.

    void writedata(char *data,int len) because the length of the passed len is the number of characters to be copied, which contains a closing flag, so when adding, subtract 1, and this is to be connected next time it is just from the position where the end flag is located (or the next run is the position of the newpos ending flag).

    The complete ** is attached.

    This is the result of the run.

  8. Anonymous users2024-01-31

    How do you see that the data is not appended to M pdata?

    In the second case, int data needs to be written to string in order to have the effect of 10abcd:

    void writeint(int i)

    sprintf(tmp, "%d", i);

    writedata(tmp,strlen(tmp));If you're looking at m pdata by string, it's not strlen(tmp)+1, otherwise it's +1

    WriteString also depends on whether you type it as a string or directly as a single character by memory length. There should be no "+1" and "+1" accordingly

  9. Anonymous users2024-01-30

    void writedata(void *data,int len) is just a function that can be called multiple times to write some data to m pdata.

    For example: int x=10;

    writedata(&x,2);

    char *str="abcd";

    writedata(str,5);

  10. Anonymous users2024-01-29

    Big end on the Internet. The data is: 0x16246a43 If you are executing on a Windows system, Windows uses little-endian code, and before memcpy, replace the byte order with unsigned int p=0x436a2416; Convert again.

    unsigned int p=0x436a2416;

    float i;

    memcpy(&i,&p,sizeof(p));

    printf("i=%f",i);

    The result is i=

  11. Anonymous users2024-01-28

    What's wrong with you, haven't you achieved it?

  12. Anonymous users2024-01-27

    Yes, memcpy function, void *memcpy(void *dest, const void *src, size t n);

    Header files are required.

    #include #include

    The specific usage is as follows:

    int a[10];

    int b[10];

    memcpy(a,b,10*sizeof(int));Assign a 10*sizeof(int) in the b array to the content

    Forget to mention that the destination array should not be smaller than the length to be copied, otherwise it will cause memory access errors or other unpredictable errors.

  13. Anonymous users2024-01-26

    There is no assignment that can only be one element at a time.

  14. Anonymous users2024-01-25

    Is there a word frequency statistic?

    Don't need to align an array of dictionaries?

    For the following characters:

    string str = "hello";

    Output this format? :

    Or is it something like this? :[1,1,2,1]

  15. Anonymous users2024-01-24

    With ASCII code, eg.

    char s = "12345";

    int c = s[2];

    Then the value of c is 3, because the ASCII code of 0 9 is the same as the number it represents.

  16. Anonymous users2024-01-23

    You're converting to a hexadecimal number.

    But it's achievable, and I've done it before, **here:

    int str16toint(char s)return temp;

    void hextostr( const char *ssrc, char *sdest, int nsrclen )

    return ;

    void hexstrtobyte(const char* source, unsigned char* dest, int sourcelen)

    return ;}

  17. Anonymous users2024-01-22

    string s = "485729304";

    int a = new int[;

    for(int i = 0;The data in the i < i++) string must be a number, otherwise an exception will occur; Get the value of the string i position and convert the char type to a string.

    Convert from string to integer

  18. Anonymous users2024-01-21

    It's simple, just like the order in which you allocate the space:

    for (int i=0; i<3; +i)

    That's fine, just make sure to get the pointer right.

  19. Anonymous users2024-01-20

    It turned out to be this kind of second-level pointer instead of a two-dimensional array ......

    Make a loop (yes), calculate the position, and then copy for(int i = 0; i < 3; +i)

Related questions
8 answers2024-03-27

Go to the library and look for it, and find a lot of it.

13 answers2024-03-27

Convert nvarchar to decimal and then float, e.g

declare @vnum varchar(20) >>>More

9 answers2024-03-27

Use the byval keyword to indicate that the parameter is passed by value, but your first argument is written by byref, which is passed by address, and the second argument is written at nothing, and it is also passed by address by default.

11 answers2024-03-27

To be clear, only"Value parameters and variable parameters"How can I help you?

14 answers2024-03-27

1. PMMA barrel temperature feeding area 60 80 (70).

District 1 150 200 (190). >>>More