PacktPublishing / Extreme-C

Extreme C, published by Packt
MIT License
314 stars 129 forks source link

copying array vs copying int cost and performance in c #4

Open sina-grz opened 3 years ago

sina-grz commented 3 years ago

hi there, I have been reading the Extreme C book, following paragraph seems to be wrong or unclear(take look at this question ).

Surprisingly, passing the pointer is not efficient in the above example! That's because of the fact that the int type is 4 bytes and copying it is more efficient than copying 8 bytes of its pointer. But this is not the case regarding structures and arrays. Since copying structures and arrays is done byte-wise, and all of the bytes in them should be copied one by one, it is usually better to pass pointers instead.

as I know all the operations in CPU are limited to arithmetic(plus or minus) or bit-wise kind of operation. and all the copying operations are bitwise at least in new cpu's.

I would be thankful if you take a look at my question at stack overflow.

kamcpp commented 2 years ago

Hi, sorry for the late reply. Let me first read your question and the answers on SO. I guess you have a point here. I'll let you know and if the statement turns out to be wrong, we will fix it in the upcoming edition or Packt will publish it as part of an Errata on their website (hopefully). Many thanks for your attention.