Comments (4)
Hello @p4w4n , I am thinking about a special data structure with framing but i'm not yet sure it's worth adding as you can do this yourself by simply placing the length of the data structure before the data structure in a byte-based Ring Buffer, then reading only the size of the length, and based on that reading out the variable length data structure itself.
If you want the ability to resynchronize if you accidentally read more or less, you can create a framing protocol yourself with a magic value at the start/end.
from lockfree.
Thanks @DNedic, this is what I did to make it compatible with my use case. I have defined a metadata structure with a size parameter.
struct ElementMetadata {
size_t size; // Size of the element data, excluding this metadata
};
and then updated Read, Write and Peek functions:
Read:
ElementMetadata metadata;
// Assuming _data is a char pointer to the buffer
memcpy(&metadata, &_data[r], sizeof(ElementMetadata));
size_t cnt = metadata.size;
r = (r + sizeof(ElementMetadata)) % size; // Advance past metadata
Write:
ElementMetadata metadata{cnt};
memcpy(_data + w, &metadata, sizeof(ElementMetadata));
w += sizeof(ElementMetadata);
This code won't be compatible with the generic implementation though.
from lockfree.
I don't really see this applicable for anything but a byte buffer, and since lockfree
is templated by type stored for all data structures so far, I don't think it would be a great fit.
Also, the byte buffer itself would require a reinterpret cast before passing the pointer to the trivial type the user wants to store, making for an ugly API.
I might create a C library for this in another repo as I see it a better fit there.
from lockfree.
I've thought about this problem some more, and here's what you can do: use a byte BipartiteBuf
, store the size of the string or your data structure, then memcpy the data structure itself. When reading, acquire a read, read the length and then if there is enough bytes available left over, memcpy out that number of bytes into your data structure. Of course, you need to use a trivially copy-able type.
from lockfree.
Related Issues (7)
- README should mention C++20 is needed to run tests HOT 1
- There are no 'How it works' sections in data structure READMEs HOT 2
- Queue size can be dynamically specified through the constructor HOT 4
- Comipe error of missing header file of std::pair<> in "bipartitte_buf.hpp" HOT 1
- Are the tests done using multiple threads? HOT 3
- Visual Studio expands the __cplusplus macro to 199711L by default regardless of C++ std being used. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lockfree.