Add memory-efficient byte writing methods to IBsonWriter interface

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Description:

      Could the IBsonWriter interface support adding the following methods to enable better memory allocation avoidance at the upper layer?
       

      void WriteBytes(byte[] bytes, int offset, int length)
      void WriteBytes(ReadOnlySpan<byte> bytes) 

      Motivation:Currently, when writing byte data through IBsonWriter, upper-layer code often needs to perform additional memory allocations or array copying operations. Adding these overloads would allow: # Slice-based writing: WriteBytes(bytes, offset, length) enables writing a portion of an existing byte array without creating a new array

      1. Span-based writing: WriteBytes(ReadOnlySpan<byte>) provides modern, allocation-free API for writing memory segments
         

        1. ConsoleApp28.zip
          4 kB
        2. image-2025-07-28-11-09-27-018.png
          image-2025-07-28-11-09-27-018.png
          172 kB

            Assignee:
            Boris Dogadov
            Reporter:
            gary chan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: