c++11 - Squish A Bunch Of Arrays Together C++ -


is there way take 2 pieces of heap allocated memory, , put them efficiently? more efficient following?

for( unsigned int = 0; < length_0; ++i )     addtoarray( buffer, array0[ ] ); for( unsigned int = 0; < length_1; ++i )     addtoarray( buffer, array1[ ] ); 

for copying memory byte byte, can't go wrong memcpy. that's going fastest way move memory.

note there several caveats, however. one, have manually ensure destination memory big enough. have manually compute sizes of objects (with sizeof operator). won't work objects (shared_ptr comes mind). , it's pretty gross looking in middle of otherwise elegant c++11.

your way works , should fast.

you should consider c++'s copy algorithm (or 1 of siblings), , use vectors resize on fly. use iterators, nicer. again, should fast memcpy, added benefit far, far safer moving bytes around: shared_ptr , ilk work expected.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -