AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Generating unique random integers
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Tue Jul 15, 2008 9:20 pm    Post subject: Reply with quote

Laszlo wrote:
I don't remember the details... Their descriptions: http://msdn.microsoft.com/en-us/library/ms802981.aspx

This will find the single set bit (run length = 1) next to bit 4:
Code:
DllCall(@SetBits, UInt,&B, UInt,1, UInt,4)
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Wed Jul 16, 2008 2:46 am    Post subject: Reply with quote

Hi Laszlo,

1.
I see from msdn that they use only 2-3 params (what needed)
to run the rtl functions,

why in AHK dllCall, AHK uses some more params, like UInt or &B ?
what thtes param's are giving ?

2. I see from msdn AND logic or OR logic between 2 bitmap var's :
InterlockedAnd
Code:

The InterlockedAnd routine atomically computes a bitwise AND operation.

LONG
  InterlockedAnd (
    IN OUT LONG volatile  *Destination,
    IN LONG  Value
    );


what is the syntax in AHK to run this function ?

rgrds
Ell
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Wed Jul 16, 2008 2:58 am    Post subject: Reply with quote

See the AHK Help for dllcall. (Each parameter is preceeded by its type.)

The interlocked functions provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads, so I don't think it makes sense from AHK.
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Wed Jul 16, 2008 6:40 am    Post subject: Reply with quote

1.
my project I run from AHK for other usage,
and also I am not familier with C or C++ compilers

will it run with AHK on the bitmap var you defined with the Initbitmap ?


2.
what you mentioned varibale for multi thread (??)
what I need it for ?

3. I saw in AHK help, the types,
so what Types I put for the bitmap var's to bitlogic AND and OR ?

rgrds
EL
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Wed Jul 16, 2008 3:02 pm    Post subject: Reply with quote

The InterlockedAnd function only AND's an integer (the second parameter) to the 4 bytes in a memory location, specified by the address given in the first parameter. It should work with individual words of the bitmap buffer (not with the whole bitmap at once), but you can do it with standard AHK commands:
Code:
offs = 0 ; the offset in the bitmap buffer
toAnd = 0xff ; the value to AND to a word in the buffer
NumPut(NumGet(y,offs) & toAnd, y, offs)
As I said, from AHK you don't normally need interlocking, used for synchronizing access to a variable that is shared by multiple threads.

The bitmap header, which represents the bitmap, is referenced by its address (&B). In 32-bit Windows addresses are 32-bit unsigned integers: UInt types.
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Wed Jul 16, 2008 10:32 pm    Post subject: Reply with quote

continueing your approach:

I want to make bitlogic AND between 2 bitmap var's in AHK

(both initilized let say 128mb)

what is the syntax command to do the AND between var1 and var2,
and put the result in third bitmap var (also 128mb) ?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Wed Jul 16, 2008 11:29 pm    Post subject: Reply with quote

Bitwise-and (&)
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Thu Jul 17, 2008 2:32 am    Post subject: Reply with quote

You have to loop through each word in their buffers
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Fri Jul 18, 2008 7:44 am    Post subject: Reply with quote

you mean to run on each bit in bitmap var (128mb) and make
the numget function in AHK you pointed ?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Jul 18, 2008 1:44 pm    Post subject: Reply with quote

No. I meant: each "word". They can contain 8-16-32-64 bits each. The offset you increment in the NumPut/NumGet example by 1, 2, 4 or 8.
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Fri Jul 18, 2008 2:09 pm    Post subject: Reply with quote

how is the syntax loop on each 64 bits
to make the bit logic AND or OR between 2 bitmap vars (128mb)
and put result in third bitmap var (128mb) ?
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Tue Jul 22, 2008 4:39 pm    Post subject: Reply with quote

Hi Laszlo,
can you send syntax code how I build the loop on word (64)
on bitmap var (128mb) ?

how I iterate on next 64 bits on whole 128mb ?

my knowledge in such kind of syntax is poor.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Jul 25, 2008 12:53 am    Post subject: Reply with quote

This is how you can find the common elements of two bitmaps:
Code:
; YOUR SIZE-PARAMETERS HERE
Bits = 66                              ; BitMap buffer size
Bytes := ceil(Bits/8)

; ALLOCATE NECESSARY MEMORY
VarSetCapacity(A, 8, 0)                ; Bitmap header always 8 bytes
VarSetCapacity(B, 8, 0)
VarSetCapacity(x, Bytes, 0)            ; Bitmap buffer
VarSetCapacity(y, Bytes, 0)

; INITIALIZE BITMAPS
DllCall("ntdll\RtlInitializeBitMap", UInt,&A, UInt,&x, UInt,Bits)
DllCall("ntdll\RtlInitializeBitMap", UInt,&B, UInt,&y, UInt,Bits)

; SET SOME BITS IN THE BITMAPS
DllCall("ntdll\RtlSetBits", UInt,&A, Uint,55, Uint,9) ; Set bits 56..64 (0-based index)
DllCall("ntdll\RtlSetBits", UInt,&B, Uint,60, Uint,5) ; Set bits 61..65 (0-based index)

; 'AND' THE BITMAP B to A, Byte-by-Byte [COMMON ELEMENTS --> A]
Loop % Bytes
   NumPut(NumGet(&x-1,A_Index,"UChar") & NumGet(&y-1,A_Index,"UChar"), &x-1, A_Index, "UChar")

; SHOW THE RESULT
Loop % Bits
   S .= DllCall("ntdll\RtlAreBitsSet", UInt,&A, Uint,A_Index-1, Uint,1, UChar)
MsgBox % S
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Fri Jul 25, 2008 7:28 pm    Post subject: Reply with quote

bitlogic on 2 bitmap var's
1. looking great

2. how I set the 'AND' of A and B to C ?
means : C = (A AND B)

3. is it possible to SET bitmap vars one to other means:
C := A
so all contest of A copy to C ?
Back to top
View user's profile Send private message
rani



Joined: 18 Mar 2008
Posts: 95

PostPosted: Fri Jul 25, 2008 7:39 pm    Post subject: Reply with quote

additinal to previous:

1. how is the command to bitlogic A 'OR' B ?

2. on the 128mb bitmap var,
I can make same commands as you posted on your 'AND' example ?

iI still didn't tested it, but the results of 'AND' or 'OR'
looping will give immediate results (non waiting) ?

3. what is the number I set as bitmap var capacity of 1GB ?
or more ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 5 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group