# win_array_to_buf()

Copies data from an array into a Windows memory buffer.

## Prototype

win_array_to_buf(data_array, memhandle, first_point, count)

## Parameters

data_array (POINTER(c_ushort))

The C array containing the data to be copied

memhandle (int)

This must be a memory handle that was returned by win_buf_alloc() when the buffer was allocated. The data will be copied into this buffer.

first_point (int)

Index of the first point in the memory buffer where data will be copied to.

count (int)

Number of data points to copy.

## Notes

- This function copies data from an array to a Windows global memory buffer. This would typically be used to initialize the buffer with data before doing an output scan. Using the first_point and count parameters it is possible to fill a portion of the buffer. This can be useful if you want to send new data to the buffer after a BACKGROUND + CONTINUOUS output scan has been started – for example, during circular buffering.
- Although this function is available to Python, it is not necessary, since it is possible to manipulate the memory buffer directly by casting the memhandle returned from win_buf_alloc() to the appropriate type. This method avoids having to copy the data from an array to a memory buffer.
- Refer to the following example:

From pyul import ul
count = 1000

# Allocate the buffer and cast it to an unsigned short
memhandle = ul.win_buf_alloc(count)
data_array = ctypes.cast(memhandle, ctypes.POINTER(ctypes.c_ushort))

# Calculate and store the waveform
for i in range(0, count):

data_array[i] = 2047 * (1.0 + math.sin(6.2832 * i / count))

# Output the waveform
ul.a_out_scan(0, 0, 0, count, 100, ULRange.BIP5VOLTS, memhandle, 0)
# Free the buffer and set the data_array to None
ul.win_buf_free(memhandle)
data_array = None