search

Home  >  Q&A  >  body text

php kernel memcpy puzzle

    /* concatenates "bar" after the newly reallocated large enough "FOO" */
    memcpy(ZSTR_VAL(foobar) + ZSTR_LEN(FOO), ZSTR_VAL(bar), ZSTR_LEN(bar));
学习ing学习ing2869 days ago863

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-07-03 11:42:51

    void* memcpy(void * destination, const void * source, size_t num);

    This operation is to connect "bar" to the newly reallocated space "FOO",
    where ZSTR_VAL returns char*, ZSTR_LEN returns int .

    Pointers can be understood as memory addresses. The pointer at the head of the existing space is ZSTR_VAL(foobar). Adding the length of space FOO backwards is the memory address at the end of FOOspace. Start from here. Memory copy, assign the value of bar (that is, ZSTR_VAL(bar)), and the length is ZSTR_LEN(bar).

    reply
    0
  • Cancelreply