Comments (9)
There is more pointer trickiness here. I'm doing the best I can to make sure it's smooth.
Basically, the getters can internally use the getPrimaryHeader()
, getTlmHeader()
, getCmdHeader()
functions, but the setters can't. It's not safe to return a pointer from a function (Hello segfaults!). Therefore those functions have to return a copy. (I can't remove those altogether, as 900Relay uses them.)
from ccsds_xbee.
All done. 900Relay should be updated to use the new library, but it isn't time critical.
from ccsds_xbee.
If I'm understanding correctly... returning a pointer from a function is allowed, but it dangerous to return the pointer to a local variable because you can't be sure what the compiler is going to do with that memory after the end of the function execution, correct? For these functions, it looks like you're taking that risk with the getters because reading a random piece of memory won't cause a problem, whereas writting to it probably would. Am I understanding correctly?
from ccsds_xbee.
Right on the first part.
Not quite on the getters: they don't need a pointer at all, they're happy with a copy of the data. So that's what they use. And it falls out of scope as soon as the function returns, so the memory hit isn't bad.
from ccsds_xbee.
This implementation is probably fine... I'm just intellectually curious now...
Why not have the field getters/setters declare the header pointer and have the getPrimaryHeader, getTlmHeader, getCmdHeader take that in as an argument and fill it? Then the pointer wouldn't be owned by getPrimaryHeader, getTlmHeader, getCmdHeader and would last for the duration that the field getter/setter needed it, correct?
from ccsds_xbee.
Also, apparently declaring a local variable static will cause the compiler to reserve its space in memory at compile-time... so you wouldn't have to worry about it being something else after the function returned. Would that be another solution here?
from ccsds_xbee.
Both would be, I believe. The former is probably the right way to do this. The reason I went with this implementation was just for backward compatibility (since we're a day away from launch). But in future we can change that.
from ccsds_xbee.
No worries and I completely agree... I was just trying to figure out what was going on
from ccsds_xbee.
Yup, all good!
from ccsds_xbee.
Related Issues (8)
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 ccsds_xbee.