ArrayArrayArray BrainModular BrainModular Users Forum 2015-04-27T10:47:08+02:00 https://www.brainmodular.com/forums/app.php/feed/topic/4882 2015-04-27T10:47:08+02:00 2015-04-27T10:47:08+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32522#p32522 <![CDATA[arrays/vectors stuff question]]>

Statistics: Posted by 23fx23 — 27 Apr 2015, 10:47


]]>
2015-04-27T10:30:03+02:00 2015-04-27T10:30:03+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32521#p32521 <![CDATA[arrays/vectors stuff question]]>
i think you should call PXY.reserve(32); before allocating your iterator vector<TPointF>::iterator IT = PXY.begin();
because reserve invalidate the iterator.

see here, Iterator validity section near the bottom of the page

Statistics: Posted by martignasse — 27 Apr 2015, 10:30


]]>
2015-04-25T23:32:53+02:00 2015-04-25T23:32:53+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32504#p32504 <![CDATA[arrays/vectors stuff question]]> then i tought i understood the use of 'new' command, and globally all worked as espected.

but then i had/have a bit more complex stuff to do like insert some variable lengths and datas , shift ,reorder, inc/dec ect the arrays.
it quicly became imo a nightmare to handle, so i think i was not looking in good dir and tried vectors instead of arrays.
seems to be much more appropiate but i really fail on that one;

what i did, is creating a TPointF vector in header file: (PXY) represents an array of points with XY coords.
[c]
#include <vector>
using namespace std;

vector<TPointF> PXY;
[/c]

i have a private class variable Psize i set to 4 on init , adjust the vector size then whenever its is resized in the code calling this:

PXY.resize(Psize); // maybe i should just allocate confortable room and don't worry?

--kk evertyhing ok for now. then i do some insert/ puch back stuff and so on pocedures ie like:
[c]
if ((Psize + 3) < Psize_Max)
{
vector<TPointF>::iterator IT = PXY.begin();
PXY.reserve(32);
int ID_AT = FIND_NEXT_MAIN(X, Y); // function that returns me an int ID of the next main point

TPointF * PXY3 = new TPointF[3]; //creating an array of points i wanna insert
PXY3[0].x = X - Test_Radius*1.5;
PXY3[0].y = Y;
PXY3[1].x = X;
PXY3[1].y = Y;
PXY3[2].x = X + Test_Radius*1.5;
PXY3[2].y = Y;

for (int i = 0; i < 3; i++) //inserting the points
{
PXY.insert(IT + ID_AT - 1 + i, PXY3);
}
// then here is the problem, i could just make : Psize = Psize+3 but i dlike to understand why this don't work:

---------------> Psize = (int)PXY.size;

[/c]
it returns me this error:
Erreur54error C2440: 'cast de type' : impossible de convertir de 'unsigned __int64 (__cdecl std::vector<TPointF,std::allocator<_Ty>>::* )(void) throw() const' en 'int'E:USINE PATCHSensomusic SDK 6.04.002examplesBEZIER_MAPPERBEZIER_MAPPER.cpp12461BEZIER_MAPPER


what im doing wrong/miss, anybody knows what's the easiest way to get a Vector size as an integer? seems basic but i struggle :(

Statistics: Posted by 23fx23 — 25 Apr 2015, 23:32


]]>
BrainModular BrainModular Users Forum 2015-04-27T10:47:08+02:00 https://www.brainmodular.com/forums/app.php/feed/topic/4882 2015-04-27T10:47:08+02:00 2015-04-27T10:47:08+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32522#p32522 <![CDATA[arrays/vectors stuff question]]>

Statistics: Posted by 23fx23 — 27 Apr 2015, 10:47


]]>
2015-04-27T10:30:03+02:00 2015-04-27T10:30:03+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32521#p32521 <![CDATA[arrays/vectors stuff question]]>
i think you should call PXY.reserve(32); before allocating your iterator vector<TPointF>::iterator IT = PXY.begin();
because reserve invalidate the iterator.

see here, Iterator validity section near the bottom of the page

Statistics: Posted by martignasse — 27 Apr 2015, 10:30


]]>
2015-04-25T23:32:53+02:00 2015-04-25T23:32:53+02:00 https://www.brainmodular.com/forums/viewtopic.php?t=4882&p=32504#p32504 <![CDATA[arrays/vectors stuff question]]> then i tought i understood the use of 'new' command, and globally all worked as espected.

but then i had/have a bit more complex stuff to do like insert some variable lengths and datas , shift ,reorder, inc/dec ect the arrays.
it quicly became imo a nightmare to handle, so i think i was not looking in good dir and tried vectors instead of arrays.
seems to be much more appropiate but i really fail on that one;

what i did, is creating a TPointF vector in header file: (PXY) represents an array of points with XY coords.
[c]
#include <vector>
using namespace std;

vector<TPointF> PXY;
[/c]

i have a private class variable Psize i set to 4 on init , adjust the vector size then whenever its is resized in the code calling this:

PXY.resize(Psize); // maybe i should just allocate confortable room and don't worry?

--kk evertyhing ok for now. then i do some insert/ puch back stuff and so on pocedures ie like:
[c]
if ((Psize + 3) < Psize_Max)
{
vector<TPointF>::iterator IT = PXY.begin();
PXY.reserve(32);
int ID_AT = FIND_NEXT_MAIN(X, Y); // function that returns me an int ID of the next main point

TPointF * PXY3 = new TPointF[3]; //creating an array of points i wanna insert
PXY3[0].x = X - Test_Radius*1.5;
PXY3[0].y = Y;
PXY3[1].x = X;
PXY3[1].y = Y;
PXY3[2].x = X + Test_Radius*1.5;
PXY3[2].y = Y;

for (int i = 0; i < 3; i++) //inserting the points
{
PXY.insert(IT + ID_AT - 1 + i, PXY3);
}
// then here is the problem, i could just make : Psize = Psize+3 but i dlike to understand why this don't work:

---------------> Psize = (int)PXY.size;

[/c]
it returns me this error:
Erreur54error C2440: 'cast de type' : impossible de convertir de 'unsigned __int64 (__cdecl std::vector<TPointF,std::allocator<_Ty>>::* )(void) throw() const' en 'int'E:USINE PATCHSensomusic SDK 6.04.002examplesBEZIER_MAPPERBEZIER_MAPPER.cpp12461BEZIER_MAPPER


what im doing wrong/miss, anybody knows what's the easiest way to get a Vector size as an integer? seems basic but i struggle :(

Statistics: Posted by 23fx23 — 25 Apr 2015, 23:32


]]>