Ruslan-B / FFmpeg.AutoGen

FFmpeg auto generated unsafe bindings for C#/.NET and Core (Linux, MacOS and Mono).
GNU Lesser General Public License v3.0
1.34k stars 315 forks source link

Change for loop to Buffer.MemoryCopy #291

Closed zhoupc2015 closed 10 months ago

zhoupc2015 commented 10 months ago

To improve performance, add the manually controllable macro HAS_SYSTEM_MEMORY_COPY, which can change the code from a for loop to the form of Buffer.MemoryCopy. For example, the method ToArray of the structure bytearray61440: public byte[] ToArray() { var a = new byte[61440]; for (uint i = 0; i < 61440; i++) a[i] = [i]; return a; } becomes public byte[] ToArray() { var a = new byte[61440];fixed (byte* src = _, dst = a){ Buffer.MemoryCopy(src, dst, 61440, 61440); } return a; }

zhoupc2015 commented 10 months ago

sorry, I should remove the commits of [Merge branch 'master']

Ruslan-B commented 10 months ago

you think faster? i did consider that but from .net5 makes no difference - in aspect of api - it is intresting, just wander if it actually is but have to powerfull system cant mesure it reliably. across versions of ffmpeg api.

zhoupc2015 commented 10 months ago

You are right, it's great to learn from you, thank you! I ran my test method a little more, and it’s exactly what you said. I’m sorry.

Ruslan-B commented 10 months ago

No sorry needed. we come covered it here as community ;)