Alex Rivera | Logout

Can I check in C(++) if an array is all 0 (or false)?

Asked 2010-10-28T15:45:13.873
9

Can I check in C(++) if an array is all 0 (or false) without iterating/looping over every single value and without allocating a new array of the same size (to use memcmp)?

I'm abusing an array of bools to have arbitrary large bitsets at runtime and do some bitflipping on it

Edit
Report

1 Answer

0

knittl,

I don't suppose you have access to some fancy DMA hardware on the target computer? Sometimes DMA hardware supports exactly the operation you require, i.e. "Is this region of memory all-zero?" This sort of hardware-accelerated comparison is a common solution when dealing with large bit-buffers. For example, some RAID controllers use this mechanism for parity checking.

answered 2010-10-28T19:04:33.793

Your Answer