uInt nrOfValues, nrNeeded, nrAvailable;// nr of data values float* pData = floatarr; // ptr to data to be handled Char* pBuffer; // ptr to buffer DynBuffer buffer; // create buffer buffer.allocstart(); // prepare for storing nrNeeded = nrOfValues; // nr of values to store // copy data into dynamic buffer while (nrNeeded > 0) { nrAvailable = buffer.alloc (nrNeeded, sizeof(float), pBuffer); // get buffer space: // room for nrAvailable values memcpy (pBuffer, pData, nrAvailable*sizeof(float)); // copy that many data values nrNeeded -= nrAvailable; // how much more needed? pData += nrAvailable; // pointer to as yet unstored data } // Maybe store more values . . // Retrieve all the data values from the buffers and write them buffer.nextstart(); // goto buffer start while (buffer.next (nrAvailable, pBuffer)) { // get next buffer write (fd, nrAvailable, pBuffer); // write data from that buffer }
Remove the whole buffer, i.e. the first buffer and all the buffers appended to it.
Prepare for storing data (re-initialize the buffer)
Allocate buffer space for nrOfValues values of size valueSize bytes, and return the pointer ptr to the buffer and the number of values that fit in the buffer.
When not all values fit in the current buffer, new buffer space is added (probably non-contiguous). If that allocation fails an exception is thrown.
Remove buffer nrOfBuffer and the buffers appended to it, and re-initialize the current buffer. By default we keep the first buffer (i.e. the one numbered 0).
The idea is that you may want to free intermediate storage space taken up by data that you no longer need, and that the first buffer is often big enough to hold further data. So, you only remove the first buffer in special cases.
Prepare for data retrieval (set up for looping through the buffers).
Get the pointer to the next buffer and its used length in bytes. The function returns a False value if there are no more buffers.
The new current buffer can be the present one (if it has free space), the next buffer already allocated (if there is one), or a newly allocated and linked-in buffer. If, in the last case, the allocation fails an exception is thrown.