我想要或兩個大塊的內存......但它不起作用內存塊之間的邏輯運算?
考慮我有三個char * bm,bm_old和bm_res。
#define to_uint64(buffer,n) {(uint64_t)buffer[n] << 56 | (uint64_t)buffer[n+1] << 48 | (uint64_t)buffer[n+2] << 40 | (uint64_t)buffer[n+3] << 32 | (uint64_t) buffer[n+4] << 24 | (uint64_t)buffer[n+5] << 16 | (uint64_t)buffer[n+6] << 8 | (uint64_t)buffer[n+7];}
...
for (unsigned int i=0; i<bitmapsize(size)/8; i++){
uint64_t or_res = (to_uint64(bm_old,i*8)) | (to_uint64(bm,i*8));
memcpy(bm_res+i*sizeof(uint64_t), &or_res, sizeof(uint64_t));
}
bm_res不正確!
有什麼線索?
謝謝,
埃米爾。
爲什麼不簡單地'reinterpret_cast'緩衝區? –
@ K-ballo,嚴格來說這是未定義的行爲。但它也比這更簡單也可能更快... – bdonlan
@ K-ballo:那會是UB。 –