- //COPY data from managed buffer to unmanaged mem pointer
- Marshal.Copy(buffer, offset, initial_pointer, (int)length);
- current_position += length;
+ // use Marshal.WriteByte since that allow us to start writing
+ // from the current position
+ for (int i = 0; i < count; i++)
+ Marshal.WriteByte (initial_pointer, (int) current_position++, buffer [offset + i]);
+
+ if (current_position > length)
+ length = current_position;