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;








2















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?










share|improve this question





















  • 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

















2















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?










share|improve this question





















  • 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













2












2








2








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?










share|improve this question
















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?







c memory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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





    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












  • 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







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












2 Answers
2






active

oldest

votes


















6














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.






share|improve this answer




















  • 1





    Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!

    – clmno
    Mar 27 at 5:20


















1














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!






share|improve this answer





























    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
    );



    );













    draft saved

    draft discarded


















    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









    6














    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.






    share|improve this answer




















    • 1





      Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!

      – clmno
      Mar 27 at 5:20















    6














    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.






    share|improve this answer




















    • 1





      Thank you. Found this other question which points to a few implementations. Also, cheers on Ripple!

      – clmno
      Mar 27 at 5:20













    6












    6








    6







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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












    • 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













    1














    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!






    share|improve this answer































      1














      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!






      share|improve this answer





























        1












        1








        1







        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!






        share|improve this answer















        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!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        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






























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현