本帖最后由 sinco449 于 2011-10-27 18:41:46 编辑

解决方案 »

  1.   

    补充一下,抛出的异常是“out of memory”
      

  2.   

    怎么没个人回复一下?难道现在用Delphi的人越来越少了,Delphi走向灭亡了
      

  3.   

    10 * 1024 * 1024 =10G
    windows只给进程最大3G空间不到
      

  4.   

    SetLength(Buf, 0 );你这个操作应该把Buf释放了 .去掉这个吧
      

  5.   


    楼上说得有道理。客户端从服务器接收到的压缩数据就是靠以上那部分代码进行解压缩的,客户端和服务器的通信是很频繁的,每次都申请、释放动态内存,确实效率不高。应该是在客户端初始化的时候就申请这么一块动态内存,使用它的时候先清空,再填充数据。客户端关闭的时候,释放这块内存。改起来,有些麻烦:因为这部分代码是被一个类似于TIDTCPServer的自定义控件类TXmlVisitServer所调用的。客户端的哪些模块需要和服务器通信的时候,就使用一个TXmlVisitServer实例,所以客户端可能同一时刻存在着多个TXmlVisitServer实例。要让这些TXmlVisitServer在调用MyunCompressFormWebService的时候,共享同一块动态内存。那问题就来了,如何申请和释放这个共享内存?在MyunCompressFormWebService里加入计数器,统计当前存活的TXmlVisitServer实例?
      

  6.   


    我不明白在SetLength(Buf, MySize )”之前来一个“SetLength(Buf, 0 )”的意义。去掉它有什么改善吗?程序不是我写的,但它现在由我维护,维护得越久就发现里面很多不合理的地方,有些涉及到基础架构的地方,我也懒得理了,反正这个程序的用户量不是很大。
      

  7.   

    才10M而已,
    SetLength(Buf, 0 );这不是害人吗?
    Unit 
    System Syntax 
    [Delphi] procedure SetLength(var S: string; NewLength: Integer);
    Description 
    S is a Delphi string or dynamic-array variable.
     
    NewLength is the new number of characters or elements in S.
     
    For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.
     
    For a long-string or dynamic-array variable, SetLength reallocates the string or array referenced by S to the given length. Existing characters in the string or elements in the array are preserved, but the content of newly allocated space is undefined. The one exception is when increasing the length of a dynamic array in which the elements are types that must be initialized (strings, Variants, Variant arrays, or records that contain such types). When S is a dynamic array of types that must be initialized, newly allocated space is set to 0 or nil.
     
    For dynamic arrays, SetLength may take more than one length parameter (up to the number of array dimensions). Each parameter specifies the number of elements along a particular dimension.
     
    Following a call to SetLength, S is guaranteed to reference a unique string or array—that is, a string or array with a reference count of one. If there is not enough memory available to reallocate the variable, SetLength raises an EOutOfMemory exception.