Vector

Hello,
iI just learned that vector.h is not part of the avrg++ library.

So what do i do, when i need to use a "dynamic" array then?

Don't. That is not a good idea with 2K of RAM.

KeithRB:
Don't. That is not a good idea with 2K of RAM.

hmm. so then what's the general approach on the situations where you don't know the size of the array?

AZZ:
hmm. so then what's the general approach on the situations where you don't know the size of the array?

Allocate the maximum size that you can tolerate at compile time and only use what you need. Use a variable to specify the size instead of sizeof().

aarg:
Allocate the maximum size that you can tolerate at compile time and only use what you need. Use a variable to specify the size instead of sizeof().

i feel i'm going to be laughed at, but still i'll try:
why not to sizeof() ? sizeof operator - cppreference.com looks legit to me.

It is legit but not for this purpose. You need to know how much you have used, not what the maximum size is - you should already know the maximum size.
However, do NOT exceed the size of your Arduino's memory!

By the way, that was a valid question and I am not laughing.

vaj4088:
It is legit but not for this purpose. You need to know how much you have used, not what the maximum size is - you should already know the maximum size.
However, do NOT exceed the size of your Arduino's memory!

so i do need to learn the old style memalloc/free workflows to be able to work with the boards?

so i do need to learn the old style memalloc/free workflows

No; it's because malloc/free doesn't work well in low-memory systems that you need to avoid high-level containers like C++ vectors in the first place. You have to go back even further:

static const MAXPOINTS = 50;         // maximum number of points allowed
point_type mypoints[MAXPOINTS];  // static storage for all of them
int current_points = 0;       // how many points actually have been added

void add_point(point_type point)
{
   mypoints[current_points] = point;
   current_point += 1;
}

(ok, maybe not THAT far back; you can wrap a nice C++ object around things. But the idea is to avoid any dynamic allocation of memory at all.)

westfw:
No; it's because malloc/free doesn't work well in low-memory systems that you need to avoid high-level containers like C++ vectors in the first place. You have to go back even further:

static const MAXPOINTS = 50;         // maximum number of points allowed

point_type mypoints[MAXPOINTS];  // static storage for all of them
int current_points = 0;      // how many points actually have been added

void add_point(point_type point)
{
  mypoints[current_points] = point;
  current_point += 1;
}




(ok, maybe not THAT far back; you can wrap a nice C++ object around things. But the idea is to avoid any dynamic allocation of memory at all.)

westfw:
No; it's because malloc/free doesn't work well in low-memory systems that you need to avoid high-level containers like C++ vectors in the first place. You have to go back even further:

static const MAXPOINTS = 50;         // maximum number of points allowed

point_type mypoints[MAXPOINTS];  // static storage for all of them
int current_points = 0;      // how many points actually have been added

void add_point(point_type point)
{
  mypoints[current_points] = point;
  current_point += 1;
}




(ok, maybe not THAT far back; you can wrap a nice C++ object around things. But the idea is to avoid any dynamic allocation of memory at all.)

got it . thank you!