由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ | A memory allocation question
相关主题
顶这锅盖总结:Java/C#萨克斯,只有C/C++才是真正的low latencyan interview question
谁编过snmp 的程序?动态语言把我绕晕了--javascript
有没有人在Vista下试过UDP广播c++posix多线程问题请教
有人了解socket error 10013吗?[bssd]我说句实话吧
我也请问一个multi-thread的问题Re: question about wireless network
相关话题的讨论汇总
话题: bcbuffer话题: char话题: question话题: c++
进入Programming版参与讨论
1 (共1页)
k**l
发帖数: 2966
1
I use a queue (deque) to store some broadcast messages for later process.
All messages were casted to char array with certain length.
say when I got a new broadcast with length n;
char* bcbuffer = new char [n];
memcpy(bcbuffer,broadcast,n);
m_broadcastQue.push(std::pair(bcbuffer,n));
Later when I process it:
char* bcbuffer =m_broadcastQue.front().first;
int n=m_broadcastQue.front().second;
m_broadcastQue.pop();//cut the link to free queue lock
processOneBroadCast(bcbuffer, n);
delete [] bcbuffer;
My question is: will the last line of code work---if it doesn't, how do I
tell the process the size of to be delete array is n?
Note: I skipped mutex lock and conditional wait stuff to make my question
easy to read.
t****t
发帖数: 6806
2
yes, it will, as long as there is no race condition.
i***c
发帖数: 26
3
delete [] bcbuffer and delete bcbuffer are the same here I think, for char
needn't deconstruction function.
t****t
发帖数: 6806
4
just don't do that.

【在 i***c 的大作中提到】
: delete [] bcbuffer and delete bcbuffer are the same here I think, for char
: needn't deconstruction function.

1 (共1页)
进入Programming版参与讨论
相关主题
我也请问一个multi-thread的问题Re: question about wireless network
an interview question顶这锅盖总结:Java/C#萨克斯,只有C/C++才是真正的low latency
动态语言把我绕晕了--javascript谁编过snmp 的程序?
c++posix多线程问题请教有没有人在Vista下试过UDP广播
[bssd]我说句实话吧有人了解socket error 10013吗?
相关话题的讨论汇总
话题: bcbuffer话题: char话题: question话题: c++