Does memmove use dynamic memory for its temporary arraymemcpy() vs memmove()Why is Linux memmove() implemented the way it is?How do I determine the size of my array in C?With arrays, why is it the case that a[5] == 5[a]?How does free know how much to free?Creating a memory leak with JavaWhat does the C ??!??! operator do?Why memory functions such as memset, memchr… are in string.h, but not in stdlib.h with another mem functions?Why is Linux memmove() implemented the way it is?Why is memmove faster than memcpy?Segmentation fault with large, contiguous 2D array (with dynamic memory allocation) in Cusing memmove in dynamic allocation in c
Why is Chromosome 1 called Chromosome 1?
ESTA declined to the US
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Making pause in a diagram
Based on what criteria do you add/not add icons to labels within a toolbar?
Does a jail-cell need a mezuzah?
12V lead acid charger with LM317 not charging
Did Apollo leave poop on the moon?
Where in ש״ס who one find the adage, “He who suggests the idea should carry it out”?
Is there such thing as a "3-dimensional surface?"
How do I get the =LEFT function in excel, to also take the number zero as the first number?
Does the Voyager team use a wrapper (Fortran(77?) to Python) to transmit current commands?
Why should I "believe in" weak solutions to PDEs?
Why does putting a dot after the URL remove login information?
Getting an entry level IT position later in life
How to halve redstone signal strength?
How to realistically deal with a shield user?
I was contacted by a private bank overseas to get my inheritance
ATPL - Principles of Flight - Question regarding propeller pitch
Why can I log in to my Facebook account with a misspelled email/password?
How can glass marbles naturally occur in a desert?
Responding to Plague Engineer
Probably terminated or laid off soon; confront or not?
Did Captain America make out with his niece?
Does memmove use dynamic memory for its temporary array
memcpy() vs memmove()Why is Linux memmove() implemented the way it is?How do I determine the size of my array in C?With arrays, why is it the case that a[5] == 5[a]?How does free know how much to free?Creating a memory leak with JavaWhat does the C ??!??! operator do?Why memory functions such as memset, memchr… are in string.h, but not in stdlib.h with another mem functions?Why is Linux memmove() implemented the way it is?Why is memmove faster than memcpy?Segmentation fault with large, contiguous 2D array (with dynamic memory allocation) in Cusing memmove in dynamic allocation in c
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
According to C11 N1570 standard draft:
7.24.2.2 "The memmove
function":
The
memmove
function copiesn
characters from the object pointed to bys2
into the object pointed to bys1
. Copying takes place as if then
characters from the object pointed to bys2
are first copied into a temporary array ofn
characters that does not overlap the objects pointed to bys1
ands2
, and then then
characters from the temporary array are copied into the object pointed to bys1
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?
c memory
add a comment |
According to C11 N1570 standard draft:
7.24.2.2 "The memmove
function":
The
memmove
function copiesn
characters from the object pointed to bys2
into the object pointed to bys1
. Copying takes place as if then
characters from the object pointed to bys2
are first copied into a temporary array ofn
characters that does not overlap the objects pointed to bys1
ands2
, and then then
characters from the temporary array are copied into the object pointed to bys1
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?
c memory
1
Tryltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)
– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
1
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try outltrace
for sure.
– clmno
Mar 28 at 11:45
add a comment |
According to C11 N1570 standard draft:
7.24.2.2 "The memmove
function":
The
memmove
function copiesn
characters from the object pointed to bys2
into the object pointed to bys1
. Copying takes place as if then
characters from the object pointed to bys2
are first copied into a temporary array ofn
characters that does not overlap the objects pointed to bys1
ands2
, and then then
characters from the temporary array are copied into the object pointed to bys1
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?
c memory
According to C11 N1570 standard draft:
7.24.2.2 "The memmove
function":
The
memmove
function copiesn
characters from the object pointed to bys2
into the object pointed to bys1
. Copying takes place as if then
characters from the object pointed to bys2
are first copied into a temporary array ofn
characters that does not overlap the objects pointed to bys1
ands2
, and then then
characters from the temporary array are copied into the object pointed to bys1
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?
c memory
c memory
edited Mar 27 at 7:07
Antti Haapala
91.4k17 gold badges177 silver badges215 bronze badges
91.4k17 gold badges177 silver badges215 bronze badges
asked Mar 27 at 5:08
clmnoclmno
8995 silver badges18 bronze badges
8995 silver badges18 bronze badges
1
Tryltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)
– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
1
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try outltrace
for sure.
– clmno
Mar 28 at 11:45
add a comment |
1
Tryltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)
– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
1
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try outltrace
for sure.
– clmno
Mar 28 at 11:45
1
1
Try
ltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
Try
ltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
1
1
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try out
ltrace
for sure.– clmno
Mar 28 at 11:45
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try out
ltrace
for sure.– clmno
Mar 28 at 11:45
add a comment |
2 Answers
2
active
oldest
votes
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.
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
add a comment |
The memmove
is not a single implementation in modern compilers; it is considered an intrinsic instead. It is easiest to show with an example how the "as if" works:
#include <string.h>
void test_memmove(void * restrict dst, const void * restrict src, size_t n)
memmove(dst, src, n);
the restrict
in parameters tell that the memory accessed through the pointers do not overlap. So GCC knows to compile this to
test_memmove:
jmp memcpy
Because the compiler was able to take the restrict
into account and "prove" that the memory areas pointed to by these 2 do not overlap, the call to memmove
was immediately changed to a (tail) call to memcpy
!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370165%2fdoes-memmove-use-dynamic-memory-for-its-temporary-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
add a comment |
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.
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
add a comment |
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.
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.
answered Mar 27 at 5:09
David SchwartzDavid Schwartz
144k14 gold badges153 silver badges238 bronze badges
144k14 gold badges153 silver badges238 bronze badges
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
add a comment |
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
1
1
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!
– clmno
Mar 27 at 5:20
add a comment |
The memmove
is not a single implementation in modern compilers; it is considered an intrinsic instead. It is easiest to show with an example how the "as if" works:
#include <string.h>
void test_memmove(void * restrict dst, const void * restrict src, size_t n)
memmove(dst, src, n);
the restrict
in parameters tell that the memory accessed through the pointers do not overlap. So GCC knows to compile this to
test_memmove:
jmp memcpy
Because the compiler was able to take the restrict
into account and "prove" that the memory areas pointed to by these 2 do not overlap, the call to memmove
was immediately changed to a (tail) call to memcpy
!
add a comment |
The memmove
is not a single implementation in modern compilers; it is considered an intrinsic instead. It is easiest to show with an example how the "as if" works:
#include <string.h>
void test_memmove(void * restrict dst, const void * restrict src, size_t n)
memmove(dst, src, n);
the restrict
in parameters tell that the memory accessed through the pointers do not overlap. So GCC knows to compile this to
test_memmove:
jmp memcpy
Because the compiler was able to take the restrict
into account and "prove" that the memory areas pointed to by these 2 do not overlap, the call to memmove
was immediately changed to a (tail) call to memcpy
!
add a comment |
The memmove
is not a single implementation in modern compilers; it is considered an intrinsic instead. It is easiest to show with an example how the "as if" works:
#include <string.h>
void test_memmove(void * restrict dst, const void * restrict src, size_t n)
memmove(dst, src, n);
the restrict
in parameters tell that the memory accessed through the pointers do not overlap. So GCC knows to compile this to
test_memmove:
jmp memcpy
Because the compiler was able to take the restrict
into account and "prove" that the memory areas pointed to by these 2 do not overlap, the call to memmove
was immediately changed to a (tail) call to memcpy
!
The memmove
is not a single implementation in modern compilers; it is considered an intrinsic instead. It is easiest to show with an example how the "as if" works:
#include <string.h>
void test_memmove(void * restrict dst, const void * restrict src, size_t n)
memmove(dst, src, n);
the restrict
in parameters tell that the memory accessed through the pointers do not overlap. So GCC knows to compile this to
test_memmove:
jmp memcpy
Because the compiler was able to take the restrict
into account and "prove" that the memory areas pointed to by these 2 do not overlap, the call to memmove
was immediately changed to a (tail) call to memcpy
!
edited Mar 27 at 7:13
answered Mar 27 at 7:06
Antti HaapalaAntti Haapala
91.4k17 gold badges177 silver badges215 bronze badges
91.4k17 gold badges177 silver badges215 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370165%2fdoes-memmove-use-dynamic-memory-for-its-temporary-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try
ltrace
, read glibc source, read GCC source, step debug the assembly, and pray that it does not go too deep :-)– Ciro Santilli 新疆改造中心996ICU六四事件
Mar 28 at 10:52
1
@CiroSantilli新疆改造中心六四事件法轮功 This was for an embedded application (and.. that's why I was too concerned about the memory), but will try out
ltrace
for sure.– clmno
Mar 28 at 11:45