我定义了一个buffer 10M,一个实时信号A,不断的往buffer里写数据。同时,buffer里的数据通过socket发往客户端。
但是A每次写数据的速度和大小都比用send()要快,大小要大。
这样的话,在一定时间后,buffer就会溢出。导致程序崩溃!请高手指点,我应该如何来设计这部分缓存。

解决方案 »

  1.   

    1. The prior level of the 'write' thread should be lower than the 'send' thread as possible.2. The buffer looks like a stack, so you can set a maximum stack size for prevent overflow for the buffer area. for example:
    if the buffer was 10M, the maximum stack size would be 10M. 
    this means that you should record the change of the stack size when the 'write' thread constantly write data into the buffer, and the 'send' thread constantly send data to client.
    Once the current stack size is equivalent or greater than 10M then the 'write' thread should be set to wait until the size of is down.
    PS. Using message or event to do the wait that should be better.
      

  2.   

    Using TLS I thought if could.
      

  3.   

    如果可以的话,可以用MSN聊一下吗?这个问题真的困扰我很久了。
    [email protected]
    发mail也可以