Re:一个关于String的问题

[复制链接]
查看11 | 回复2 | 2021-1-29 05:17:04 | 显示全部楼层 |阅读模式
发信人:[email protected](ss),信区:Java标题:Re:一个关于String的问题发信站:我爱南开站(SunSep2911:21:592002)转信站:PKUBBS!news2.happynet.org!news.happynet.org!NanKai
Java的String也是一个只读的类,那些修改String的操作都会创建新的String实例。String应该是很大的,具体多少不好说,不过我觉得没必要考虑这个问题,真创建特别大的String,程序恐怕早Outofmemory了,根本不可能觉得String对大小有限制。如果程序要占很多内存,肯定需要自己写一个缓冲模块,以前写过这种模块,当时程序就能处理200多M的图形文件,用SCSI硬盘,速度也可以。
share (98CS~~番木瓜~~淡出~~) 在 ta 的帖子中提到:一次插入若干字符和逐个插入情况不同吧。不太懂java,在C#中改变string的值实际上是新建了string实例,反复操作2000多次难免出现资源一时回收不过来的情况,【在ahdoh(小辉)的大作中提到:】:这个我没有仔细测试过也没看过规范的文档。:我曾经用String变量接受从sql数据库里读出的字符,大约在2000字符:左右就是上限了不过你可以自己测试一下。:写一个循环语句然后每次循环都插入一个字符在异常处理的时候打印:循环的变量就可以了。(比较笨的法子。).................(以下省略)
回复

使用道具 举报

千问 | 2021-1-29 05:17:04 | 显示全部楼层
自己试了个大概,然后上网查了一下,发现确实没错这个网站有几乎所有人类研究过的数列,当然也有这个http://www.research.att.com/~njas/sequences/
hawking (我死了) 在 ta 的帖子中提到:真牛啊,我看了半天找不出通式,你怎么看出来的:)

回复

使用道具 举报

千问 | 2021-1-29 05:17:04 | 显示全部楼层
constintcodes=4096;constintByteSize=8;constintexcess=4;constintalpha=256;constintmask=15;unsignedchars[codes];intsize;intleftOver;intstatus=0;classelement{public:intprefix;unsignedcharsuffix;elementoperator=(elemente){prefix=e.prefix;suffix=e.suffix;}};elementh[codes];FILE*in;FILE*out;voidsetFiles(){charinPutFile[100];charoutPutFile[100];chartemp[20];strcpy(inPutFile,D:\\);strcpy(outPutFile,D:\\);coutinputnameoffiletodecompress(Omittheextension.zzz);cintemp;strcat(inPutFile,temp);strcat(outPutFile,temp);/*coutinputformatofdecompressedfile;cintemp;if(!strchr(inPutFile,temp)){strcat(outPutFile,.);strcat(outPutFile,temp);}*/strcat(inPutFile,.zzz);if((in=fopen(inPutFile,rb))==NULL){cerrcannotopeninPutFile;exit(1);}out=fopen(outPutFile,wb);}
voidoutPut(intcode){size=-1;while(code=alpha){s[++size]=h[code].suffix;code=h[code].prefix;}s[++size]=h[code].suffix;for(inti=size;i=0;i--){fputc(s[size],out);}}boolgetCode(intcode){unsignedcharc,d;c=fgetc(in);if(feof(in))returnfalse;if(status){code=(leftOverByteSize)|c;}else{d=fgetc(in);code=(cexcess)|(dexcess);leftOver=dmask;//problem?}status=1-status;returntrue;}
voiddeCompress(){intused=alpha;intpcode;intccode;if(getCode(pcode)){s[0]=pcode;fputc(s[0],out);size=0;while(getCode(ccode)){if(ccodeused){outPut(ccode);if(usedcodes){h[used].prefix=pcode;h[used++].suffix=s[size];}}else{h[used].prefix=pcode;h[used++].suffix=s[size];outPut(ccode);}pcode=ccode;}}fclose(in);fclose(out);}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行