Functions > di_buffer_alloc

Syntax

The di_buffer_alloc function allocates a memory block to temporarily store channel data.

Syntax

int _huge *di_buffer_alloc(chn,size);

unsigned chn;

/* specifies whether buffer is for input (0) or output (1) data */

unsigned size;

/* words to allocate for buffer */

 

For DI-1100, DI-1110, DI-1120, DI-2008, DI-2108, DI-2108P, DI-4108, DI-4208, or DI-4718B to allow high-speed operation of devices that support synchronized scanning, you can specify an input buffer size of 0 to allocate 0x10000L samples times the number of devices of the same model or compatible models supported by the DLL opened by di_open. None of these devices support an output buffer.

Parameters

chn

0 = input

1 = output

Note: Output functions are not available on all instruments. Check your hardware manual for output specifications.

The least significant bit of chn is the only bit checked to determine input or output.

size

The di_buffer_alloc function allocates a memory block of at least size words (1 word = 1 sample).

Return Value

The di_buffer_alloc function returns a huge integer pointer if it can allocate memory of size and if a buffer has not been previously allocated for chn. NULL is returned if allocation fails.

Dependencies

di_open

di_inlist or di_outlist

Remarks

It is a good idea to allocate a size divisible by the total number of channels. Larger buffer sizes minimize the probability of an overrun at high sample rates. Maximum buffer size is always 65535 16-bit words. Use the following table to determine minimum buffer size. 

  Instrument If allocating only one buffer If allocating an Input and Output buffer
  Input Buffer Output Buffer
  DI-194, DI-145, DI-148, DI-149, DI-158, DI-71x* 4096 N/A N/A
  DI-220 Series 8182 4091 4091
  DI-400 Series 15000 8192 6144
  DI-700* 64 N/A N/A
  DI-500, DI-720, DI-730, DI-5001 Printer Port Devices 7500 4096 4096
  DI-500, DI-720, DI-730, DI-78x, DI-5001 Ethernet Devices 7500 N/A N/A
  DI-500, DI-720, DI-730, DI-78x, DI-5001 USB Devices 15000 N/A N/A
  * Input buffer only supported

De-allocate the memory block with di_buffer_free.

For DI-1100, DI-1110, DI-1120, DI-2008,DI-2108, DI-2108P, DI-4108, or DI-4208 to allow high-speed operation of devices that support synchronized scanning, you can specify an input buffer size of 0 to allocate 0x10000L samples times the number of devices of the same model or compatible models supported by the DLL opened by di_open. None of these devices support an output buffer.

Sample Code

#include "200sdk.h"

int *input_buffer;

int *output_buffer;

main()

{

di_open ();

if((input_buffer = di_buffer_alloc(0,4096)) == NULL)

/* allocate input buffer */

printf("Insufficient memory or input buffer already allocated...\n");

if((output_buffer = di_buffer_alloc(1,4096)) == NULL)

/* allocate output buffer */

printf("Insufficient memory or output buffer already allocated...\n");

di_close ();

}

 

Copyright © DATAQ Instruments, Inc.