Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::move data out of DynamicMemoryWriter when GetReader called #376

Open
Brett208 opened this issue Jan 18, 2021 · 1 comment
Open

std::move data out of DynamicMemoryWriter when GetReader called #376

Brett208 opened this issue Jan 18, 2021 · 1 comment

Comments

@Brett208
Copy link
Member

Likely blocked until issue #375 is implemented. See PR #373 for additional discussion.

Currently calling 'DynamicMemoryWriter::GetReader' provides access to data within DynamicMemoryWriter without transferring ownership.

Currently you should never attempt to clear DynamicMemoryWriter's internal stored data for future writes in case a Reader is still referencing the content. This can be avoided procedurally by always creating a new instance of DynamicMemoryWriter after GetReader is called for future dynamic memory reads. Some discussion if the procedural approach is actually more appropriate than adding a clear type concept to DynamicMemoryWriter.

I did try to add a Clear function to DynamicMemoryWriter before understanding the relationship of shared data between the Reader and Writer although that may not be in line with how others would intuitively try to use DynamicMemoryWriter.

Example Clear command for future consideration:

// Clear all currently set memory
void DynamicMemoryWriter::Clear() {
	SeekBeginning();
	streamBuffer.clear();
}
@DanRStevens
Copy link
Member

To add a bit of detail, it is possible to switch back and forth between writing or clearing and reading, just that you always want to create a new reader object after a write or clear operation. This is similar how updates to a container can invalidate iterators traversing the container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants