New topic: 

Code Speed

<http://forums.realsoftware.com/viewtopic.php?t=38381>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        trice          Post subject: Code SpeedPosted: Tue Mar 29, 2011 
12:32 pm                         
Joined: Thu Dec 02, 2010 10:17 pm
Posts: 30                Code:  dim chrdata as String
  for i as integer=1 to data.LenB Step 2
  dim CurrentValue as integer=Val(MidB(data,i,2))
  chrdata=chrdata+right(ChrB(CurrentValue),1)
  next
I have that code right there. It works fast for smaller values but when i have 
a value over 200,000 bytes it locks up the application. Could I get some help 
on how to speed it up   
                             Top                 timhare          Post subject: 
Re: Code SpeedPosted: Tue Mar 29, 2011 12:39 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 9584
Location: Portland, OR  USA                Isn't that code just picking out 
every other character?  You seem to be doing a lot of converting for nothing.   
                             Top                trice          Post subject: 
Re: Code SpeedPosted: Tue Mar 29, 2011 12:46 pm                         
Joined: Thu Dec 02, 2010 10:17 pm
Posts: 30                well It's actually taking a stream of numbers and 
turning every ascii value and turning it into its ascii character.   
                             Top                 DaveS          Post subject: 
Re: Code SpeedPosted: Tue Mar 29, 2011 12:57 pm                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 2884
Location: San Diego, CA                don't re-dim the "currentvalue" move it 
outside the loop... that might help...
plus remember strings are immuteable.... so you are building a new string each 
time
so at 200000 chars... to add one char takes 400001 bytes for that action.
think about perhaps using a pre-defined memoryblock instead.....

Also.... why bother with all this?  if you are extracting pairs of 
characters... then the value cannot exceed 99... and 0 to 127 is inside the 
ASCII encoding.... or did I miss something here?

Code: dim chrdata as String
dim currentvalue as integer
  for i as integer=1 to data.LenB Step 2
   CurrentValue =Val(MidB(data,i,2))
  chrdata=chrdata+right(ChrB(CurrentValue),1)
  next



Also.... why bother with all this?  if you are extracting pairs of 
characters... then the value cannot exceed 99... and 0 to 127 is inside the 
ASCII encoding.... or did I miss something here?

can't it just be
Code: dim chrdata as String
  for i as integer=1 to data.LenB Step 2
  chrdata=chrdata+ChrB(Val(MidB(data,i,2)))
  next
      
_________________
Dave Sisemore
MacPro, OSX 10.6.4 RB2009r5.1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to