I'm trying to see if a struct came back as all 0xFF
for the size of the struct.
memcmp
seems like the obvious starting point, BUT I'd have to allocate a second memory block, populate it with 0xFF
's. It just seems like a waste.
Does a standard function exist for this? Or should I just punt and iterate via a for loop?
The most obvious solution here seems to be to simply loop over the size of the struct and compare it byte-by-byte.
The approach of allocating a block of 0xFF
followed by memcmp
should achieve the same with but a higher space complexity.
I know no standard function for this.
I don't think that memcmp
is always the right choice (it needs twice the memory bandwith).
I would write an iteration (even a very naive one). Most compilers optimize that very well (when asked). So they probably unroll your loops and may do word compares (even if you coded a naive byte iteration).
You might code specialized openmp variants (at least on GCC). See http://openmp.org/
If the structure is big (e.g. dozens of kilobytes, because of the cost of GPGPU <-> RAM data copy) and if you have lot of development time to waste, consider perhaps OpenCL (in particular if you have specialized hardware supporting it, e.g. GPGPUs). It might never worth the cost (unless you do something -which does not require a lot of memory bandwidth- on the CPU while the GPGPU is working)
I would code the naive loop, and won't bother optimizing by hand (unless benchmarking of compiler-optimized code suggests otherwise), because the bottleneck is probably the memory bandwidth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With