The memory space for a user-defined stream structure and its buffer
are controlled by the user application. It is recommended to use
QP_malloc()
to allocate the space for more efficient memory utilization
in the Prolog system. In our example, the buffer is a field
in the BinStream
structure so that only one QP_malloc()
call
allocates both buffer and stream space.
After memory is allocated, the fields in the stream structure
are set appropriately.
The fields of QP_stream
part in the stream structure
is set up in the next step.
if ((stream = (BinStream *) QP_malloc(sizeof(*stream))) == ((BinStream *) 0) ) { (void) close(fd); *error_num = QP_errno; return QP_NULL_STREAM; } stream->fd = fd; stream->last_rdsize = 0;