Many Win32 functions require the use of structures and I have developed my own system for creating & accessing structures. It may not be pretty OR safe but it is fast. A necessary part of using structures is allocating & releasing small blocks of memory. This is a (relatively) time consuming exercise. On my P150 I get 14.3 seconds using allocate() & free() for 1,000,000 small blocks of memory ~ 70k/s. However, where possible I am directly reusing the structure memory for an associated function within a management routine. This can significantly boost the performance of the routine since the overhead of extra allocate() & free() calls is avoided. I have now started using a permanently allocated RAM scratchpad for some functions which (i) could be called a lot and (ii) I would not expect to be interrupted by another call which would use (therefore corrupt) the same memory. In some instances I am getting 1.26 seconds ~ 790k/s. In the case of allocating & pokeing null terminated text strings the result is 3.42 seconds ~ 290k/s and is 4 times faster than allocate_string() & free() but, of course, without any safety barrier (other than the size of the buffer) to prevent corruption of the referenced memory.
Although only a small number of structures (approx. 25) have been defined in structures.ew I think the library is still quite capable for many purposes. I will add more structure definitions as time goes on and the need for them becomes apparent.
Structure definitions can ONLY be added to this file since the functions to create them are local to that include file. Additional structures can be defined in 2 easy steps: --
step 1) define the name of the structure as a constant. I always use the Win32 API names.eg:
constant RECT = new_struct(),
RECT_left = struc(C_LONG), RECT_top = struc(C_LONG), RECT_right = struc(C_LONG), RECT_bottom = struc(C_LONG)
To ascertain the size of the structure in bytes simply call sizeofstruct(STRUCTNAME), eg:
lpRect = allocate( sizeofstruct( RECT ) )
-- Define PAINTSTRUCT Structure PAINTSTRUCT = new_struct(), PAINTSTRUCT_hdc = struc(C_LONG), PAINTSTRUCT_fErase = struc(C_SHORT), PAINTSTRUCT_rcPaint = struc(RECT), -- ***** note the use of RECT here!! PAINTSTRUCT_fRestore = struc(C_SHORT), PAINTSTRUCT_rgbReserved = struc(anySize(32)),
ps = allocate(sizeofstruct(PAINTSTRUCT)) -- do some code rFlag = peek4u(ps + PAINTSTRUCT_fRestore) -- rFlag now has the value of the Restore flag
top = peek4u(ps + PAINTSTRUCT_rcPaint + RECT_top )