add two char*

I'm coding in c/c++
is there a way to concatenate two char* fast instead of memcpy each time perhaps in c++ ??
I don't want to use strcpy/str function because its a buffer for md5 (in fact its a unsigned char*)


thanks
What does it mean to concatenate two pointers?
Perhaps the pointers refer to the first elements of two 16-byte arrays, and you want to concatenate those?
What's wrong with std::memcpy or std::memmove as appropriate?
Last edited on
ok.. this is kind of fail, so long as we understand that up front.

why not use c++ strings or vector of unsigned int?

if that is no good, you can roll your own. If there is a performance problem, you can multi-thread the copy and you can move at least 8 bytes at a time via casting hax (turn them into 64 bit ints). Some systems now support 16 byte ints, but that probably takes assembly language to make the efficient copy xpoit. If you multi threaded it and used the integer trick on a typical PC (4 cpu cores ) you could move at least 32 bytes at a time, and that probably happening at close to 50 to 100 million (each 32 bytes!) per second. The encryption stuff will take far longer than the bit copy stuff regardless of how you do it, but that should knock it out fast.

the bits are the same for signed or unsigned when the data is 'just bytes'. A simple cast flips between the two. So long as you are just moving it, it works either way. If you process it, it may matter, depending on what you did.

if the strings are fixed (or known for each) length, you could just store them in a single buffer that is already concat ... if the data is 'bytes'. If they are truly null terminated strings this won't work.



Last edited on
when I mean fast I mean when typing but what the point of using std:memcpy if it has the same parameter than memcpy

dest - pointer to the memory location to copy to
src - pointer to the memory location to copy from
count - number of bytes to copy
this is lame lol
Last edited on
what the point of using std::memcpy if it has the same parameter than memcpy

Both ::memcpy and std::memcpy are equivalent, except the latter is preferred as a member of the standard namespace.

(In any case std::copy is a better choice, but you're asking about memcpy.)

when I mean fast I mean when typing

If you want terse code, start by avoiding built-in arrays. C++ provides the tools required to do this compactly, but C does not.
Last edited on
Registered users can post here. Sign in or register to post.