Accessing memory error
Hello,
I am writing a program and it is compiled without any error. However, when I run that program, it is showing the error below.
1 2 3
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
| |
How can I solve that problem?
Your app ran out of memory.
Without seeing the code it's difficult to tell.
Even if my main is simple like the following codes, it is still showing the same error message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "simulator.h"
#include <thread>
#include <vector>
#include <iostream>
void printThread(const std::shared_ptr<Simulator> &sim)
{
while(true)
{
Pose aircraftPose = sim->getFriendlyPose();
std::cout << "printed" << std::endl;
}
}
int main(void)
{
std::vector<std::thread> threads;
std::shared_ptr<Simulator> sim(new Simulator());
threads.push_back(sim->spawn());
threads.push_back(std::thread(printThread, sim));
for(auto & t: threads){
t.join();
}
return 0;
}
| |
Based on the posted code there's no way to tell if this is a constructed thread object
|
threads.push_back(sim->spawn())
| |
You can also try using
1 2 3 4
|
for(auto & t: threads){
if(t.joinable())
t.join();
}
| |
Edit also try using emplace_back()
Last edited on
getFriendlyPose() is being called in an infinite loop. Is it allocating but not deallocating memory (directly or indirectly)?
Topic archived. No new replies allowed.