Re: Fast memcpy() ???

Discussion in 'C++' started by Ian Collins, Apr 27, 2010.

  1. Ian Collins

    Ian Collins Guest

    On 04/27/10 04:20 PM, Peter Olcott wrote:
    > I am looking for a fast memcpy() that will work well on
    > 32-bit machines for both Linux and Windows.


    What's wrong with the standard one?

    --
    Ian Collins
    Ian Collins, Apr 27, 2010
    #1
    1. Advertising

  2. On 2010-04-27, Peter Olcott <> wrote:
    >
    > "Ian Collins" <> wrote in message
    > news:...
    >> On 04/27/10 04:20 PM, Peter Olcott wrote:
    >>> I am looking for a fast memcpy() that will work well on
    >>> 32-bit machines for both Linux and Windows.

    >>
    >> What's wrong with the standard one?
    >>
    >> --
    >> Ian Collins

    >
    > Is it smart enough to copy 32 bits at a time, even when the
    > memory is not aligned on a 32 bit boundary?
    >


    If you aren't sure, it would be trivial to write a wrapper
    that would copy the first %32 bits manually then copy the
    remaining (32-bit aligned) memory using memcpy.

    But I would expect any library memcpy to already do this.

    --
    Andrew Poelstra
    http://www.wpsoftware.net/andrew
    Andrew Poelstra, Apr 27, 2010
    #2
    1. Advertising

  3. Ian Collins

    Jorgen Grahn Guest

    On Tue, 2010-04-27, Peter Olcott wrote:
    >
    > "Ian Collins" <> wrote in message
    > news:...
    >> On 04/27/10 04:20 PM, Peter Olcott wrote:
    >>> I am looking for a fast memcpy() that will work well on
    >>> 32-bit machines for both Linux and Windows.

    >>
    >> What's wrong with the standard one?


    > Is it smart enough to copy 32 bits at a time, even when the
    > memory is not aligned on a 32 bit boundary?


    Why don't you check for yourself?
    The one in OpenBSD is; I've read it.

    Also don't forget the one builtin to your compiler; the one that knows
    a whole lot more about the arguments than a library function does.
    Depending on what you're doing, even a perfect library function can be
    much slower.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Apr 27, 2010
    #3
  4. Ian Collins

    tonydee Guest

    On Apr 27, 11:42 pm, Andrew Poelstra <>
    wrote:
    > On 2010-04-27, Peter Olcott <> wrote:
    > > "Ian Collins" <> wrote in message
    > >news:...
    > >> On 04/27/10 04:20 PM, Peter Olcott wrote:
    > >>> I am looking for a fast memcpy() that will work well on
    > >>> 32-bit machines for both Linux and Windows.

    >
    > >> What's wrong with the standard one?

    >
    > >> --
    > >> Ian Collins

    >
    > > Is it smart enough to copy 32 bits at a time, even when the
    > > memory is not aligned on a 32 bit boundary?

    >
    > If you aren't sure, it would be trivial to write a wrapper
    > that would copy the first %32 bits manually then copy the
    > remaining (32-bit aligned) memory using memcpy.
    >
    > But I would expect any library memcpy to already do this.
    >
    > Andrew Poelstrahttp://www.wpsoftware.net/andrew


    Exactly... people have thought of all these issues decades ago... not
    just 32 bits at a time, but various things that can only be done in
    machine code inexpressible in C++, as well as loop unrolling and
    inlining, using known alignment and size information etc.... Best
    idea, forget all about it - especially if this probably ties in to
    your other thread which I got the impression was about trying to use
    memcpy() to outperform compiler-generated copy constructors or
    something...?

    Cheers,
    Tony
    tonydee, Apr 28, 2010
    #4
  5. Ian Collins

    tonydee Guest

    On Apr 28, 11:20 pm, "Peter Olcott" <> wrote:
    > I beat std::string by a factor of 125-fold once, thus I
    > expect that improvements can be made to memcpy() at least on
    > my platform.


    It's not a meaningful comparison. The design compromises in strings
    are massively more complicated than a memcpy (e.g. dynamic memory
    allocation vs embedded short strings or better suited capacity
    resizing defaults, reference counting). You won't have outperformed
    std::string because anything was simply overlooked in its
    implementation.

    Cheers,
    Tony
    tonydee, Apr 30, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Edwards
    Replies:
    1
    Views:
    569
    Dave Rahardja
    Aug 7, 2003
  2. Replies:
    0
    Views:
    646
  3. Michele Simionato

    Python is darn fast (was: How fast is Python)

    Michele Simionato, Aug 23, 2003, in forum: Python
    Replies:
    13
    Views:
    551
  4. Juha Nieminen
    Replies:
    22
    Views:
    994
    Kai-Uwe Bux
    Oct 12, 2007
  5. Öö Tiib

    Re: Fast memcpy() ???

    Öö Tiib, Apr 28, 2010, in forum: C++
    Replies:
    0
    Views:
    554
    Öö Tiib
    Apr 28, 2010
Loading...

Share This Page