-
-
Notifications
You must be signed in to change notification settings - Fork 179
Feature/cleanup rawdata #41
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
Conversation
…second copy of the same data. Small API change, if no data is available, an empty string is returned instead of a NULL. Also readValue() returns a reference to m_value now, thus saving a copy constructor and a second copy of the same string in the sketch
Well I was going to get rid of the string use all together but this works as well. |
I was a little surprised about the |
It's a nice quick way of doing allocation, but it depends on the implementation of stdlib as to how much data it actually uses. I think this one will reallocate 1.5x the amount needed but it could be 2x or more. |
I didn't know that... |
It's not a big deal as most of the time the data will be less than the 20 bytes so it probably won't reallocate up to that point. It's just when you add say another 20 bytes it will allocate 30 or more so it has space to use if you add more data, prevents too many allocations happening. |
Merging this soon, waiting for testing with semaphore changes (might need to alter code here). |
Okay, let me know if you need some changes (although this change is very straight forward) |
Been thinking about this and #49, if combined creates the possibility of a segfault. Scenario: That scenario might seem unlikely and preventable with the timestamp idea (thank you, it's great) but would require the user to properly implement the handling of it (check before reading, etc.). Also, since there is no way to know how the user application will use the pointer to From here there are 2 solutions I can see. 1 we can use a semaphore to protect the data and instead of a pointer we return a copy of the value (std::vector<uint8_t> preferably). 2 we do as already exists in master and malloc/copy the data and return a pointer to it, but implement a semaphore protection mechanism as well. Option 1 is my preference but breaks compatibility, however it also takes care of the malloc/free issue and lets the application do the work. Option 2 already exists but needs protection added. I'm open to any other solutions, this is just my current thoughts. As far as this library is concerned stability is my top priority, better to use some extra resources than crash an application IMHO. |
I fully agree with you! I have a third option. Completely remove |
Yes I believe this would be the correct option. I prefer not to break the api but in this case it seems necessary. I think in the future the read results should be changed to something else. Perhaps we could use the NimBLEValue class to provide safe data access. Then the value could be stored however and provide methods for type conversion. |
…ead of a reference (just to be sure)
Removed I think |
Yes that seems a valid option, pro: this is consistent with the server side of the library (although I do not like the incrementing of the value there, I think the main program should prepare the value and pass it in one time to the library), con: an extra layer of abstraction that is not really necessary. |
@Jeroen88 agreed! Thanks for removing the reference as well, that would have been problematic, the copy is a necessity in this case. |
@h2zero Updated to latest master and removed |
Great, thanks! |
b3a0ebe
to
a4cf80a
Compare
Previously getRawData() made an unnecessary copy of the remote characteristic value data in order to return a uint8_t*. The resources used for this was unjustified by the value it provided as templates to retrieve such data have been added. Also the application writer could cast the std::string result of readValue() and/or getValue() however they choose using the data() method on the container if desired. getDataLength() is also an unnecessary function as the length can be retrieved by the returned std::string from readValue() and/or getValue() with the length() method. Co-authored-by: h2zero <[email protected]>
Reopening #26 on new master.