AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

memory problem with StreamTokenizer

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Quick Function
Guest





PostPosted: Wed Nov 24, 2004 11:29 pm    Post subject: memory problem with StreamTokenizer Reply with quote



Hi, I am using StreamTokenizer to parser a file and it seems that
there is a memory problem with the class. Here is my code:


BufferedReader br = new BufferedReader(new FileReader(filename));
StreamTokenizer st = new StreamTokenizer(br);

//other stuff, configure tokenizer...

while ((tt = st.nextToken()) != StreamTokenizer.TT_EOF) {
if (tt == st.TT_WORD) {
saveTokenInMyStructure(st.sval);
}
}

br.close();

The file is 5M, but this piece of code takes 50M memory and does not
go away when it is out of scope. If I replace
saveTokenInMyStructure(st.sval) with saveTokenInMyStructure("Hello")
where let's assume that "Hello" is longer than any token in the file,
there is not memory problem. Why?


Thanks,

QQ
Back to top
ThomasH
Guest





PostPosted: Thu Nov 25, 2004 2:20 am    Post subject: Re: memory problem with StreamTokenizer Reply with quote



Quick Function wrote:
Quote:

Hi, I am using StreamTokenizer to parser a file and it seems that
there is a memory problem with the class. Here is my code:

BufferedReader br = new BufferedReader(new FileReader(filename));
StreamTokenizer st = new StreamTokenizer(br);

Same with the StringTokenizer, which must be made for each
line anew. My recommendation is: Write your own tokenizer on
array of char[] or byte[] or when on StringBuffer and forget
the trouble. I am not sure of StreamTokenizer, the StringTokenizer
is badly designed, that I have to write a small finite state
machine with hasMoreTokens() and getToken(), thus if you will
do well, your own scanner might even use less bytecode! Whoever
made these Java classes, has never before written a compiler...

Thomas

Quote:

//other stuff, configure tokenizer...

while ((tt = st.nextToken()) != StreamTokenizer.TT_EOF) {
if (tt == st.TT_WORD) {
saveTokenInMyStructure(st.sval);
}
}

br.close();

The file is 5M, but this piece of code takes 50M memory and does not
go away when it is out of scope. If I replace
saveTokenInMyStructure(st.sval) with saveTokenInMyStructure("Hello")
where let's assume that "Hello" is longer than any token in the file,
there is not memory problem. Why?

Thanks,

QQ

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.