Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does memmove use dynamic memory for its temporary array

Tags:

c

memory

According to C11 N1570 standard draft:

7.24.2.2 "The memmove function":

The memmove function copies n characters from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n characters from the object pointed to by s2 are first copied into a temporary array of n characters that does not overlap the objects pointed to by s1 and s2, and then the n characters from the temporary array are copied into the object pointed to by s1

So if I choose to move a buffer of size 32K using (file_size = 32K)

memmove(io_Buffer, io_Buffer+17, file_size);

won't the temp buffer be of size 32K?

Question

Can the program allocate dynamic memory on its own? Does it allocate and free the memory in that one line?

like image 724
clamentjohn Avatar asked Jul 28 '26 00:07

clamentjohn


1 Answers

I think you missed the "as if" in that sentence. That means the effects will be the same as if it did that, not that it will actually do that. I've never seen an implementation of memmove that actually uses a temporary array.

like image 121
David Schwartz Avatar answered Jul 30 '26 14:07

David Schwartz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!