我正在努力尋找一種用新數據填充緩衝區的好方法。我有一個線程從聲卡生成數據,我想通過一個名爲Rawcontainer的共享對象與其他線程共享這些數據。該容器容納一個互斥體和一個環緩衝區,但是當我嘗試填充緩衝區時,我注意到我填充緩衝區的對象都具有相同的內存地址,從而使整個緩衝區無用。多次創建新結構
void useBuffer(){
//Create a new "OBject" (struct) each time this methos is called??
SoundData *p = new SoundData();
//Copy the data of the sound into the the struct data field
memcpy(p->data, soundCopy, 2048*sizeof(double));
//Put the struct into the buffer and forget about it?
Rawcontainer->writeRaw(p);
//This should print a differnt adress each time the method is called?, but it dosent!
std::cout << "Adressse fra Streamhandler: " << &p <<'\n';
}
你想打印'p',指針。你正在打印'&p'又名「哪裏有'p'存儲」,這可能每次都是一樣的 – turbulencetoo
啊哈!非常感謝。但是,如果另一個線程正在從同一個地址讀取數據,那麼會出現問題?它對我來說都是新的指針和東西.. – user3348461
是的。會有問題。但同步是一個很大的問題。您應該閱讀文檔,或者至少打開其他問題。 – Avt