Author Topic: Fill string array  (Read 3496 times)

0 Members and 2 Guests are viewing this topic.

Aurel

  • Guest
Fill string array
« on: May 15, 2012, 11:33:20 AM »
Hi..
I hope that my question is not to trivial.
I want fill string array on quick way as possible but it looks
to me that take long time ,in my case 4 sec.
Code: [Select]
FOR Lpos = 0 TO LCount-1

pText = Space (255) 
SendMessage richedit1,EM_GETLINE,Lpos,*pText

'convert to bstring & show line in edit control
LText = pText
LText = rtrim(ltrim(LText))
LText =Mid(Ltext,1,3)
src[Lpos]=LText

Next
'array filed
print "Array filled..."

Is there a faster way maybe..?

Charles Pegge

  • Guest
Re: Fill string array
« Reply #1 on: May 15, 2012, 08:55:11 PM »
Hi Aurel,

This is faster on the Oxygen side:

Code: [Select]
string pText = Space (255) 
sys pt=strptr ptext
sys lpos,b,j,p

FOR Lpos = 0 TO LCount-1

  SendMessage richedit1,EM_GETLINE,Lpos,pt

  'convert to bstring & show line in edit control
  'LText = pText
  'LText = rtrim(ltrim(LText))
  'LText =Mid(Ltext,1,3)
  j=1
  p=pt
  do
    b=*p and 255
    if b>32 then exit do
    p++
    j++
  end do
  '
  src[Lpos]=LText=mid(pText,j,3)
Next
'array filed
print "Array filled..."

Charles

Aurel

  • Guest
Re: Fill string array
« Reply #2 on: May 15, 2012, 09:44:44 PM »
Thanks Charles i will try.. ;)
So i try...and final speed is same as you say oxygen side probably is faster but from
windows side not because SendMessage is not very fast. :-\
« Last Edit: May 15, 2012, 11:32:23 PM by Aurel »

Charles Pegge

  • Guest
Re: Fill string array
« Reply #3 on: May 16, 2012, 12:58:51 AM »
Would it help to get the whole text with WM_GETTEXT and then split it into lines using Oxygen?

A high speed line splitter:
Code: [Select]


'LINE SPLITTER
'=============

indexbase 1
string txt=nuls 100000 'buffer
string lines[100000]   'lines array
sys pt=strptr txt      'buffer base pointer
sys i.j,p              'indexes and pointer


'test data:
'==========
string cr=chr(13)+chr(10)
string lc="abc"+cr
mid (txt,1)=lc+lc+lc+lc+lc
'
'initial
'=======
'
'sendMessage richedit1,WM_GETTEXT,100000,pt
'
p=pt 'char pointer
b=0  'left boundary
i=0  'lines array index
j=1  'char index
'
byte a at p 'byte linked to pointer p
'
'splitter loop
'=============
'
do
  select a
  case 0
    exit do
  case 10
    b=j
  case 13
    b++
    i++
    lines[i]=mid(txt,b,j-b)
    b=j
  end select
  p++
  j++   
end do

print "Lines: " i cr+
      ">" lines[3] "<"

Charles
« Last Edit: May 16, 2012, 01:48:29 AM by Charles Pegge »

Aurel

  • Guest
Re: Fill string array
« Reply #4 on: May 16, 2012, 05:20:16 AM »
Hi Charles ..
This might be solution,i will try how work this way.. ;)

Aurel

  • Guest
Re: Fill string array
« Reply #5 on: May 17, 2012, 02:45:28 AM »
Hi Charles...
I try and work  :)
First block of code must be in global scope:
Code: [Select]
'must be in global scope +++++++++++++++++++++++++
string txt = nuls 100000 'buffer
string lines[100000]   'lines array
sys pt = strptr txt    'buffer base pointer
sys i.j,p              'indexes and pointer
'++++++++++++++++++++++++++++++++++++++++++++++++

Then in subroutine is loop:
Code: [Select]
Sub FillArray
print "Start..."


string cr=chr(13)+chr(10)
'init...
SendMessage richedit1,WM_GETTEXT,100000,pt

p=pt 'char pointer
b=0  'left boundary
i=0  'lines array index
j=1  'char index
'
byte a at p 'byte linked to pointer p
'
'splitter loop
'=============
'
do
  select a
  case 0
    exit do
  case 10
    b=j
  case 13
    b++
    i++
    lines[i]=mid(txt,b,j-b)
    b=j
  end select
  p++
  j++   
end do

print "Lines: " i cr+
      ">" lines[3286] "<" 

End Sub

One thing is not clear to me because number of lines in richedit is 12557 (abasic src) and
result is just 3825 lines in counter i ,next element -> lines[3286] is empty. ???

Aurel

  • Guest
Re: Fill string array
« Reply #6 on: May 17, 2012, 03:06:23 AM »
Hmm ,so nothing else then i increase buffer to :
string txt = nuls 500000 'buffer
and fill other part,is this ok?
because i don't recive any error and look that is very fast...

Charles Pegge

  • Guest
Re: Fill string array
« Reply #7 on: May 17, 2012, 06:41:36 AM »
I found this in MSDN about a 64k limitation on richedit controls.

Quote
Rich Edit: If the text to be copied exceeds 64K, use either the EM_STREAMOUT or EM_GETSELTEXT message.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632627(v=vs.85).aspx

EM_SELTEXT
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774190(v=vs.85).aspx
EM_SETSEL
http://msdn.microsoft.com/en-us/library/windows/desktop/bb788007(v=vs.85).aspx
CHARRANGE
http://msdn.microsoft.com/en-us/library/windows/desktop/bb787885(v=vs.85).aspx

I hope this helps. It sounds a little complicated to me :)

Charles

Aurel

  • Guest
Re: Fill string array
« Reply #8 on: May 17, 2012, 07:34:08 AM »
Yes i know for this limit to 64k but when i increase buffer it work fine and load 300k file without a
problem.

Charles Pegge

  • Guest
Re: Fill string array
« Reply #9 on: May 17, 2012, 07:59:14 AM »
That's good to know. Perhaps the 64k limitation only applies to earlier Windows.