[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
barrinit() Allocate bit array
------------------------------------------------------------------------------
Declaration
bit.hdr
Syntax
func _BITARRAY barrinit extern
param value ulong nElements, ;
value logical lSet
Arguments
nElements is the number of bits to allocate for the array. The maximum
size of a bit array is 500,000 elements.
lSet is a flag to indicate if bits will be set.
Return
A handle to the allocated bit array, or zero if the allocation has
failed or the nElements parameter exceeded the maximum.
Description
The barrinit() function allocates an array of bits, and initializes
all elements to the value of zero. The individual bits in the array can
be manipulated with other bit array functions. The indexing of bit array
elements is 0-based.
Bit arrays are data storage areas, allocated from runtime memory,
whose elements (bits) can be individually accessed using the provided
functions. The primary use of bit arrays is to economically store
large amounts of binary (logical) data.
Example
#define EXAMPLE_MATH
#include example.hdr
proc Test_barrinit
vardef
_BITARRAY pArr
enddef
// allocate and access array of half a million elements
pArr := barrinit( 500000UL, .f. )
? barrget( pArr, 76541UL ) // print .f.
? barrget( pArr, 76542UL ) // print .f.
? barrget( pArr, 76543UL ) // print .f.
barrset( pArr, 76542UL, .t. ) // set an element
?
? barrget( pArr, 76541UL ) // print .f.
? barrget( pArr, 76542UL ) // print .t.
? barrget( pArr, 76543UL ) // print .f.
barrclear( pArr ) // free array
endproc
proc main
Test_barrinit()
endproc
See Also: barrclear() barrget() barrset()
Online resources provided by: http://www.ClipX.Net --- NG 2 HTML conversion by Dave Pearson