search

Home  >  Q&A  >  body text

c++ - 环形缓冲区中存放结构体,实现思路是什么?

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

PHP中文网PHP中文网2803 days ago919

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 13:14:43

    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>.

    reply
    0
  • Cancelreply