malloc 指针的段错误
我正在创建一个线程类用作 pthreads 的包装器。我有一个 Queue 类用作队列,但我遇到了问题。它似乎分配和填充队列结构很好,但是当我尝试从中获取数据时,它 Seg.缺点。
http://pastebin.com/Bquqzxt0 (printf用于调试,两者都会抛出段错误)
编辑:队列存储在动态分配的“structqueueset”数组中,作为指向数据的指针和数据的索引
I'm making a thread class to use as a wrapper for pthreads. I have a Queue class to use as a queue, but I'm having trouble with it. It seems to allocate and fill the queue struct fine, but when I try to get the data from it, it Seg. faults.
http://pastebin.com/Bquqzxt0 (the printf's are for debugging, both throw seg faults)
edit: the queue is stored in a dynamically allocated "struct queueset" array as a pointer to the data and an index for the data
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C++ 为您提供了内置队列类:
在 C++ 中,避免内存问题的最佳方法是尽可能减少使用原始指针的内存管理,并在适用的情况下使用标准类。
C++ provides a built-in queue class for you:
In C++, the best way to avoid memory problems is to minimize the management of memory using raw pointers as much as possible, and use standard classes where applicable.