Skip to content

Optimise MySqlDataReader.GetStream #592

@bgrainger

Description

@bgrainger

The default implementation of DbDataReader.GetStream creates a new MemoryStream and copies the data returned by GetBytes into it, in a loop.

A better implementation would be to create a read-only MemoryStream directly on the backing store for the row.

This does raise a question about the lifetime of the Stream, though: its backing memory would be overwritten as soon as DbDataReader.Read is called again. Is there any documentation on whether consumers can use the returned Stream after calling Read again, or after closing the DbDataReader? (Since, with Connector/NET, these behaviours are implicitly allowed due to the way the Stream is created, there may well be existing code that relies on it.)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions