Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 10 months ago.
How to port std::vector<MyRect> into mbed?
Hi, I have a standard C++ function that have std::vector<MyRect> allCandidates; .
How to port std::vector<MyRect> into mbed?
Is there similar C++ Vector in mbed?
Thanks, Sung
1 Answer
6 years, 10 months ago.
Hello Sung,
Assuming that the MyRect
user data type is defined in MyRect.h and MyRect.cpp files:
- Create empty MyRect.h and MyRect.cpp files in your mbed project
- Copy and paste the code from your original files into the corresponding empty files
- Include the
<vector>
and"MyRect.h"
header file into yourmain
code - Import
std namespace
- Create and use
vectors
ofMyRect
type in your project
#include "mbed.h" #include "MyRect.h" #include <vector> using namespace std; int main(void) { vector<MyRect> myVector; MyRect myRect(0, 0, 5, 5); myVector.push_back(myRect); ... }
As long as you have #include <vector> it should work fine, that is a standard part of c++.
Having said that dynamic memory allocation structures like vectors should be avoided if possible on embedded systems, they give quite a performance hit.
posted by Andy A 16 Jun 2017