c++ - 环形缓冲区中存放结构体,实现思路是什么?
PHP中文网
PHP中文网 2017-04-17 13:12:43
0
1
931

假如有一结构体struct待存储,环形缓冲区内采用动态内存分配,那么应该采用new char[N]的方式以字节来存储结构体的字节信息,还是直接new struct[N]的方式以整体来存储结构体本身?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
黄舟

It depends on what your elements are. If the element is a struct, then use a new struct array; if it is a char, then use a new char[n].
For example, for a socket buffer, usually use a CircleBuffer<uint8> ; A message queue generally uses CircleBuffer<Message>.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template