Any tips for using span in an Update loop of a game engine? The only way I can figure out how to do it is to make local spans, but this is obviously wrong because they are constantly going out of scope, and converting back and forth from an array to a span every frame is obviously wrong (and actually tanked my framerate). Basically, how can I have a span that I can access like a field?
@manojambhore27722 жыл бұрын
Really good one Nick, waiting for your benchmark. Net video
@nickproudprogrammer2 жыл бұрын
Thanks! Glad you enjoyed it. Yes Benchmark.NET is on my list for upcoming videos. Stay tuned! :)
@danielbrown7534Ай бұрын
@@nickproudprogrammer wanted to see the memory allocation
@DuncanSmart Жыл бұрын
The main benefit of spans is reducing allocations (that you mentioned at the start) when doing stuff like string manipulation, but you didn’t enable the memory diagnoser. Not sure your example would have been very enlightening for that anyway, but maybe a follow up video on this subject would be interesting.
@nickproudprogrammer Жыл бұрын
Thank you for your feedback! I appreciate your insight on the main benefit of spans and the suggestion for a follow-up video. I'll definitely take that into consideration for future content.
@Lammot Жыл бұрын
From bad to worse: 0. You should generally try to always return the result of the bench to avoid compiler optimizations for dead code. Not going to pretend that I know what cases will it optimize away, (it obviously didn't optimize entire methods away), but point is - you don't need to guess if you just return. 1. Should've slapped [MemoryDiagnoser] attribute on the tests. 0 extra allocations is half the point of the struct. Maybe you would've seen next issue: 3. You are allocating an array for each method call at line 29. Defeats the whole purpose of having a span there in the first place. 4. You are comparing apples to oranges here. StartsWith compares via a culture specific comparer and span op_equals... 5. The span op equals will ALWAYS return false, because operator will first check the length of spans and then check if they point to the same memory. Which they obviously don't. Were you really ready to advise others on the subject?
@nickproudprogrammer Жыл бұрын
Thanks for your detailed critique. I value constructive feedback but noticed a somewhat pedantic tone. Let's keep the conversation positive and collaborative. I'll certainly consider your technical points in my future content.
@Lammot Жыл бұрын
@@nickproudprogrammer not trying to get to you personally, jfyi. I do, however, wonder how well did you understand the subject you before you posted a guide for other folks. Just plain curiosity, even if it sounds cruel. ps: future content is future content, but this video demonstrates examples that are plain wrong, which then sticks to people who are new to the subject. Are you planning to do anything about that?
@nickproudprogrammer Жыл бұрын
Fair points, although I think you could've approached it with a bit more grace. The purpose of the video was to demonstrate the differences in processing time when using span compared to similar operations. 1. MemoryDiagnoser - I've acknowledged feedback from viewers that this would be also nice to see. I simply chose to show execution time in this high level intro video. 3? (Did 2 get missed?) You're correct, this use case doesn't necessarily reflect the point of using span in the real world. Thanks for this. 4. This is your best point, and it's kindly pointed out by other viewers also. I'll put a note in the description for this and it will be central to a version 2 video when I can get to film it. 5. Same as above. Thanks for this Thanks again for helping me improve my content. I am very careful to ensure that I'm clear when I'm dispensing advice and when I'm demonstrating an example. I think there's a lot in this video which can be improved, thanks to your feedback 😊
@dr.angerous11 ай бұрын
@@nickproudprogrammerlol you suck
@mattmckinstry Жыл бұрын
What were the Allocations like for the example?
@nickproudprogrammer Жыл бұрын
Good question. Would need to profile the example to find out
@abdulj12832 жыл бұрын
Nice video Nick. Can you make your next video on Dependency Injection using C# as this concept is sometimes confusing to me. Thanks...
@nickproudprogrammer2 жыл бұрын
Thanks Abdul! Sounds good. I'll add Dependency Injection to my list. Thanks for the input :)
@SkullSkill9122 жыл бұрын
can you make an httplistener that intercepts a POST, you can edit it, and forward it?
@nickproudprogrammer2 жыл бұрын
Like a relay? Would you just be forwarding the request onto another API?
@SkullSkill9122 жыл бұрын
@@nickproudprogrammer You send a POST, intercept it to get the data but it wasnt sent to the server yet, then forward it once you got the data.
@nickproudprogrammer2 жыл бұрын
@@SkullSkill912 Sounds like you want to implement a packet sniffer! Can you explain the use case a little more? It's just that if what I think you want to do is correct, it falls within the realms of ethical (or not so ethical) hacking
@Texas_1985 Жыл бұрын
String.StartsWith by default uses a culture-sensitive comparison rule using the current culture, where as you are using an ordinal comparison in your span example. The ordinal comparison is going to be faster because you're just looking at the binary value. It would be interesting to see the benchmark again but where you use StringComparison.Ordinal as the secondary parameter in String.StartsWith.
@nickproudprogrammer Жыл бұрын
Interesting idea. Thanks!
@sebnig72702 жыл бұрын
Is it only faster for the alternative for startswith or also for contains helper function?