ARM: Using STL vectors

Hi,

I'm writing a C++ program that will run on an STM3210E-EVAL board and I'm having some problems using STL vectors. I'm wondering what I'm doing wrong. (Or if STL vectors are even supported.)

Here's a snippet:

#include <vector>

.
.
.

void func()
{
  std::vector<int> temp;

  temp.push_back(5);
}

When I try to run the debugger on my target, I end up somewhere in assembly land and never reach the beginning of my main() function. (I am not familiar with assembly so, I'm not quite sure where I am or how I got there.)

When I run in simulator mode, everything works fine. (I end up at the beginning of my main() function like I expect.)

It appears that whenever I make any command that increases the size of my vector, I get the same result. If I never insert into my vector or resize it, then the debugger brings me to the beginning of main(), like I'd expect.

The last time I saw something like this was when my heap was 0 and I tried newing something on the heap. If anyone has any ideas, I'd be grateful.

I'm required to write my program in C++ and though I'm not required to use vectors, I really would like to. (I also have a few ideas of how to implement it differently if it turns out that vectors don't work.)

Thanks,

Parents
  • I haven't tested, so I can't really help with your problem.

    But think twice about dynamic memory in an embedded application. The stl implementation may be leak-free, but not free from possible memory fragmentation.

    And unless you preallocate everything, you can't test your code and know that it will also work out in the wild. With dynamic memory, the sequence and the quantity of allocations will matter, creatly increasing the number of permutations in how your program may fail.

Reply
  • I haven't tested, so I can't really help with your problem.

    But think twice about dynamic memory in an embedded application. The stl implementation may be leak-free, but not free from possible memory fragmentation.

    And unless you preallocate everything, you can't test your code and know that it will also work out in the wild. With dynamic memory, the sequence and the quantity of allocations will matter, creatly increasing the number of permutations in how your program may fail.

Children
More questions in this forum