AutoHotkey Community

It is currently May 27th, 2012, 10:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 87 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post subject:
PostPosted: July 26th, 2008, 12:39 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
ell wrote:
how I set the 'AND' of A and B to C ?
Setup C as shown for A, or B, with its buffer z. Replace the line
Code:
NumPut(NumGet(&x-1,A_Index,"UChar") & NumGet(&y-1,A_Index,"UChar"), &x-1, A_Index, "UChar")
with
Code:
NumPut(NumGet(&x-1,A_Index,"UChar") | NumGet(&y-1,A_Index,"UChar"), &z-1, A_Index, "UChar")
(The bitwise AND is ‘&’, replaced here with the bitwise OR: ‘|’, providing the union of the two bitmaps A and B in the bitmap C.)
ell wrote:
SET bitmap vars one to other… C := A
Replace the above line with
Code:
NumPut(NumGet(&x-1,A_Index,"UChar"), &z-1, A_Index, "UChar")
ell wrote:
on the 128mb bitmap var,
I can make same commands as you posted on your 'AND' example ?
what is the number I set as bitmap var capacity of 1GB ?
It should work with any size, up to 2GB. 32-bit Windows versions do not handle more. When the physical memory is exhausted, parts of the bitmap will be swapped to disk, which is very slow.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ntdll bitmaps
PostPosted: September 29th, 2008, 11:15 pm 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Laslo

I checked in ahk and later in vb6 the ntdll bit search 'or' and 'and'
and itterate on or bits=1 in specififc ntdll
of course in ahk it was real slow.
but in VB6 I expected for much better response (immeditely)

if I want to use in my application hundreds( or even thousands)
of bitmap strings , using ntdll
how I can handle these bitmaps ?
putting all in memory in some pointer array ?

or is there some other technique to handle it ?
some internal 'database' or else ?

rgrds
rani


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2008, 11:47 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
When you create the bitmaps, you have to give them a name (an AHK variable, which contains the bitmap structure) and reserve memory for the data (other AHK variables, with the necessary VarSetCapacity calls). These variables can be array elements:
Code:
Number_of_Bits = 66 ; whatever you need
Size_in_Bytes := ceil(Number_of_Bits/8)

Loop 999 {
   VarSetCapacity(Bitmap%A_Index%, 8, 0) ; Bitmap header always 8 bytes
   VarSetCapacity(Buffer%A_Index%, Size_in_Bytes, 0) ; Bitmap buffer
   DllCall("ntdll\RtlInitializeBitMap", UInt, &Bitmap%A_Index%, UInt, &Buffer%A_Index%, UInt, Number_of_Bits)
}


Edit: fixed typo


Last edited by Laszlo on October 22nd, 2008, 3:32 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: ntdll instance
PostPosted: October 8th, 2008, 12:28 pm 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Laso,

1.
I checked the array in VB6 , and it works.

2.
is it possible to make one instance of the array of bitmap strings (thousand's)
and in other tasks (PID threads) to get /set values to this array ?
to aviod loading all array in every task opened ?
how is the technique to do that ?
by COM/DCOM maybe ?
any code sample will help
3.
is it possible to make ahk script to wrap under COM object ?
so it will be treated ad activex dll ?

thanks
ran


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 8th, 2008, 1:54 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
look here


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 9th, 2008, 8:43 pm 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Laslo

I read your link but I could not connect how to use the ntdll functions
with the rea/write memory

ran


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2008, 6:48 am 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Laslo

is it possible to wrap ahk script
as COM activex object ?
so other program can use it as DLL instance ?

rgrds
ran


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2008, 2:49 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Ask (PM) a COM expert, like Sean or Lexikos.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2008, 5:51 am 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Laszo

when I initialize the bitmap,
I want the max bits will be ,let say 500,000 or 1MB bits:
bits=500000
what is the number I set in the :
DllCall("ntdll\RtlInitializeBitMap"

it is in bits or bytes ? or k*32 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2008, 3:33 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The last parameter is the number of bits.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 10th, 2009, 5:45 am 
Laszlo wrote:
In some applications we need random numbers, which are all different. There is a simple method to generate them one by one: compare each new random number to all previously generated- and in a list stored- numbers. If no collision is found, attach the new number to the list. You can see that the running time grows at least quadratically with the length of the list, n.

Using priority queues, heaps or other complicated data structures speeds this up to n log(n). Similar expected running time can be achieved if we generate more numbers than needed, sort the list (with attached indices), so the equal numbers get next to each other. A simple scan now finds and removes repetitions. If enough numbers are left, just sort the list, now according to the original indices and we get a random sequence without repetitions. Unfortunately, we either have to write very complicated scripts or use external programs, like SORT.

But there is a way around. Hopefully, AHK uses internally those fancy data structures to find variables. Even if not, the internal search is done by compiled code, not by an interpreted script. We should achieve a great speedup by taking advantage of the variable naming capabilities of AHK. Here is how:

As the firs number is generated, say R_1 = 10, we create a variable called Index_10. We assign the index of the generated number (1 from R_1) to it. At a later stage, if we encounter the same value again, like R_8 = 10, we check Index_10. Now it exists and contains an index: 1. So, we found a repetition. We have to try generating a new R_8. If R_8 is now 9, and this is the first time the value 9 occurs, there will be no Index_9 defined, so we create it, and store the index 8 of R_8 in there.

Is there a problem here? (Think a bit before you read further.) What happens if there is an Index_9 environment variable already defined by some Windows process or by our own script, in a previous run? It is quite slow to clear all possible Index_x values before the script runs. But is it necessary?

NO! To protect ourselves from a leftover Index_9 variable, with some wrong value j in it, we check if j is a number, if it is between 1 and the current index of the generated random number (8 from R_8) and if it really points to an R_j, which has the value 9. If all these are true, we know that Index_9 is not garbage, we can safely use it.

Here is the script, which should generate unique random integers really fast.
Code:
MIN = 0
MAX = 99
N   = 10
If (Max - Min + 1 < N)
{
   MsgBox Cannot have %N% different numbers between %MIN% and %MAX%
   return
}

Loop %N%
{
  i := A_Index
  loop
  {
    Random R, %MIN%, %MAX%     ; R = random number
    j := Index_%R%             ; get value from Indexes
    If j is number
      If j between 1 and % i - 1
        If (R_%j% = R)
          continue             ; repetition found, try again
    Index_%R% := i             ; store index
    R_%i% := R                 ; store in R_1, R_2...
    break                      ; different number
  }
}
MsgBox %R_1%`n%R_2%`n%R_3%`n%R_4%`n%R_5%`n%R_6%`n%R_7%`n%R_8%`n%R_9%`n%R_10%







How do you decrease or increase the amount of random numbers produced?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2009, 4:47 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The top 3 lines set the parameters: MIN, MAX and the number of random numbers: N.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 87 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 35 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group